-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make error less brittle to fix upcoming error with HCP SDK Go changin…
…g how we return 404 error
- Loading branch information
1 parent
dddc1fb
commit cf6a82f
Showing
2 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"google.golang.org/grpc/codes" | ||
) | ||
|
||
func TestCheckErrorCode(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
codeString string | ||
expectCode codes.Code | ||
expectSuccess bool | ||
}{ | ||
{ | ||
"old format, code matches what is looked for", | ||
`{Code:5,"details":[],"message":"Error: The bucket etc."}`, | ||
codes.Code(5), | ||
true, | ||
}, | ||
{ | ||
"old format, code doesn't match what is looked for", | ||
`{Code:55,"details":[],"message":"Error: The bucket etc."}`, | ||
codes.Code(5), | ||
false, | ||
}, | ||
{ | ||
"new format, code matches what is looked for", | ||
`{"code":5,"details":[],"message":"Error: The bucket etc."}`, | ||
codes.Code(5), | ||
true, | ||
}, | ||
{ | ||
"new format, code doesn't match what is looked for", | ||
`{"code":55,"details":[],"message":"Error: The bucket etc."}`, | ||
codes.Code(5), | ||
false, | ||
}, | ||
{ | ||
"bad format, should always be false", | ||
`"ceod":55`, | ||
codes.Code(5), | ||
false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
found := CheckErrorCode(fmt.Errorf(tt.codeString), tt.expectCode) | ||
if found != tt.expectSuccess { | ||
t.Errorf("check error code returned %t, expected %t", found, tt.expectSuccess) | ||
} | ||
}) | ||
} | ||
} |