Skip to content

Commit f3c5d1f

Browse files
committed
enhancement code
1 parent 2429c9f commit f3c5d1f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

scaleway/validate_cassettes_test.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,8 @@ func TestAccScalewayCassettes_Validator(t *testing.T) {
4242

4343
func checkErrorCode(c *cassette.Cassette) error {
4444
for _, i := range c.Interactions {
45-
switch i.Code {
46-
case http.StatusInternalServerError:
45+
if !checkErrCode(i, c, http.StatusConflict, http.StatusInternalServerError) {
4746
return fmt.Errorf("status: %v founded on %s. method: %s, url %s", i.Code, c.Name, i.Request.Method, i.Request.URL)
48-
case http.StatusConflict:
49-
if !checkExceptions(c) {
50-
return fmt.Errorf("status: %v founded on %s. method: %s, url %s", i.Code, c.Name, i.Request.Method, i.Request.URL)
51-
}
5247
}
5348
}
5449

@@ -62,11 +57,22 @@ func exceptionsCassettesCases() map[string]struct{} {
6257
"testdata/data-source-rdb-privilege-basic.cassette.yaml": {}}
6358
}
6459

65-
func checkExceptions(c *cassette.Cassette) bool {
60+
func checkErrCode(i *cassette.Interaction, c *cassette.Cassette, codes ...int) bool {
6661
exceptions := exceptionsCassettesCases()
67-
_, exist := exceptions[c.File]
68-
return exist
62+
_, isException := exceptions[c.File]
63+
if isException {
64+
return isException
65+
}
66+
67+
for _, httpCode := range codes {
68+
if i.Code == httpCode {
69+
return true
70+
}
71+
}
72+
73+
return true
6974
}
75+
7076
func fileNameWithoutExtSuffix(fileName string) string {
7177
return strings.TrimSuffix(fileName, filepath.Ext(fileName))
7278
}

0 commit comments

Comments
 (0)