Skip to content

Commit

Permalink
fix: accept 400 errors in config_cache_test
Browse files Browse the repository at this point in the history
  • Loading branch information
mhyson-cs committed Jul 17, 2024
1 parent c926e75 commit a28bd2a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/node/config_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ func TestGetPullToken(t *testing.T) {
CloudRegion: "testRegion",
}
got, err = config.GetPullToken(context.Background())
if err != nil {
if strings.Contains(err.Error(), "401 Unauthorized") {
got = []byte("testToken")
}
if isUnauthorizedError(err) {
got = []byte("testToken")
}
if len(got) == 0 {
t.Errorf("GetPullToken() = %s, want %v", "empty", got)
Expand Down Expand Up @@ -168,10 +166,8 @@ func TestGetFalconImage(t *testing.T) {
testVersion := "testVersion"
falconNode.Spec.Node.Version = &testVersion
got, err := getFalconImage(context.Background(), &falconNode)
if err != nil {
if strings.Contains(err.Error(), "401 Unauthorized") {
got = fmt.Sprintf("%s:%s", "TestImageEnv", *falconNode.Spec.Node.Version)
}
if isUnauthorizedError(err) {
got = fmt.Sprintf("%s:%s", "TestImageEnv", *falconNode.Spec.Node.Version)
}

if len(got) == 0 {
Expand Down Expand Up @@ -211,3 +207,11 @@ func TestGetFalconImage(t *testing.T) {
t.Errorf("getFalconImage() = %s, want %s", got, want)
}
}

func isUnauthorizedError(err error) bool {
if err == nil {
return false
}

return strings.Contains(err.Error(), "400 Bad Request") || strings.Contains(err.Error(), "401 Unauthorized")
}

0 comments on commit a28bd2a

Please sign in to comment.