Skip to content

Commit 72f9076

Browse files
committed
fix
Signed-off-by: yuluo-yx <[email protected]>
1 parent 1478c6f commit 72f9076

File tree

1 file changed

+83
-83
lines changed

1 file changed

+83
-83
lines changed

pkg/testing/case_test.go

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -16,114 +16,114 @@ limitations under the License.
1616
package testing_test
1717

1818
import (
19-
"github.com/linuxsuren/api-testing/pkg/util"
20-
"testing"
19+
"github.com/linuxsuren/api-testing/pkg/util"
20+
"testing"
2121

22-
atesting "github.com/linuxsuren/api-testing/pkg/testing"
23-
"github.com/stretchr/testify/assert"
22+
atesting "github.com/linuxsuren/api-testing/pkg/testing"
23+
"github.com/stretchr/testify/assert"
2424

25-
"gopkg.in/yaml.v3"
25+
"gopkg.in/yaml.v3"
2626
)
2727

2828
func TestInScope(t *testing.T) {
29-
testCase := &atesting.TestCase{Name: "foo"}
30-
assert.True(t, testCase.InScope(nil))
31-
assert.True(t, testCase.InScope([]string{"foo"}))
32-
assert.False(t, testCase.InScope([]string{"bar"}))
29+
testCase := &atesting.TestCase{Name: "foo"}
30+
assert.True(t, testCase.InScope(nil))
31+
assert.True(t, testCase.InScope([]string{"foo"}))
32+
assert.False(t, testCase.InScope([]string{"bar"}))
3333
}
3434

3535
func TestRequestBody(t *testing.T) {
36-
req := &atesting.Request{}
37-
graphqlBody := `api: /api
36+
req := &atesting.Request{}
37+
graphqlBody := `api: /api
3838
body:
3939
query: query
4040
operationName: ""
4141
variables:
4242
name: rick
4343
`
4444

45-
err := yaml.Unmarshal([]byte(graphqlBody), req)
46-
assert.Nil(t, err)
47-
assert.Equal(t, `{"query":"query","operationName":"","variables":{"name":"rick"}}`, req.Body.String())
45+
err := yaml.Unmarshal([]byte(graphqlBody), req)
46+
assert.Nil(t, err)
47+
assert.Equal(t, `{"query":"query","operationName":"","variables":{"name":"rick"}}`, req.Body.String())
4848

49-
var data []byte
50-
data, err = yaml.Marshal(req)
51-
assert.Nil(t, err)
52-
assert.Equal(t, graphqlBody, string(data))
49+
var data []byte
50+
data, err = yaml.Marshal(req)
51+
assert.Nil(t, err)
52+
assert.Equal(t, graphqlBody, string(data))
5353

54-
err = yaml.Unmarshal([]byte(`body: plain`), req)
55-
assert.Nil(t, err)
56-
assert.Equal(t, "plain", req.Body.String())
54+
err = yaml.Unmarshal([]byte(`body: plain`), req)
55+
assert.Nil(t, err)
56+
assert.Equal(t, "plain", req.Body.String())
5757
}
5858

5959
func TestResponse(t *testing.T) {
60-
resp := &atesting.Response{
61-
Body: "body",
62-
BodyFieldsExpect: map[string]interface{}{
63-
"name": "rick",
64-
},
65-
}
66-
assert.Equal(t, "body", resp.GetBody())
67-
assert.Equal(t, map[string]interface{}{"name": "rick"}, resp.GetBodyFieldsExpect())
60+
resp := &atesting.Response{
61+
Body: "body",
62+
BodyFieldsExpect: map[string]interface{}{
63+
"name": "rick",
64+
},
65+
}
66+
assert.Equal(t, "body", resp.GetBody())
67+
assert.Equal(t, map[string]interface{}{"name": "rick"}, resp.GetBodyFieldsExpect())
6868
}
6969

7070
func TestSortedKeysStringMap(t *testing.T) {
71-
obj := atesting.SortedKeysStringMap{
72-
"c": "d",
73-
"f": map[string]interface{}{
74-
"value": "f",
75-
},
76-
"e": &atesting.Verifier{
77-
Value: "e",
78-
},
79-
"a": "b",
80-
}
81-
assert.Equal(t, []string{"a", "c", "e", "f"}, obj.Keys())
82-
assert.Equal(t, "b", obj.GetValue("a"))
83-
assert.Nil(t, obj.GetVerifier("b"))
84-
assert.Equal(t, "e", obj.GetValue("e"))
85-
assert.Equal(t, "f", obj.GetValue("f"))
86-
assert.Equal(t, "f", obj.GetVerifier("f").Value)
87-
assert.Empty(t, obj.GetValue("not-found"))
71+
obj := atesting.SortedKeysStringMap{
72+
"c": "d",
73+
"f": map[string]interface{}{
74+
"value": "f",
75+
},
76+
"e": &atesting.Verifier{
77+
Value: "e",
78+
},
79+
"a": "b",
80+
}
81+
assert.Equal(t, []string{"a", "c", "e", "f"}, obj.Keys())
82+
assert.Equal(t, "b", obj.GetValue("a"))
83+
assert.Nil(t, obj.GetVerifier("b"))
84+
assert.Equal(t, "e", obj.GetValue("e"))
85+
assert.Equal(t, "f", obj.GetValue("f"))
86+
assert.Equal(t, "f", obj.GetVerifier("f").Value)
87+
assert.Empty(t, obj.GetValue("not-found"))
8888
}
8989

9090
func TestBodyBytes(t *testing.T) {
91-
const defaultPlainText = "hello"
92-
const defaultBase64Text = "aGVsbG8="
91+
const defaultPlainText = "hello"
92+
const defaultBase64Text = "aGVsbG8="
9393

94-
tt := []struct {
95-
name string
96-
rawBody string
97-
expect []byte
98-
}{{
99-
name: "image base64",
100-
rawBody: util.ImageBase64Prefix + defaultBase64Text,
101-
expect: []byte(defaultPlainText),
102-
}, {
103-
name: "pdf",
104-
rawBody: util.PDFBase64Prefix + defaultBase64Text,
105-
expect: []byte(defaultPlainText),
106-
}, {
107-
name: "zip",
108-
rawBody: util.ZIPBase64Prefix + defaultBase64Text,
109-
expect: []byte(defaultPlainText),
110-
}, {
111-
name: "binary",
112-
rawBody: util.BinaryBase64Prefix + defaultBase64Text,
113-
expect: []byte(defaultPlainText),
114-
}, {
115-
name: "raw",
116-
rawBody: defaultPlainText,
117-
expect: []byte(defaultPlainText),
118-
}}
119-
for _, tc := range tt {
120-
t.Run(tc.name, func(t *testing.T) {
121-
body := atesting.RequestBody{
122-
Value: tc.rawBody,
123-
}
124-
data := body.Bytes()
125-
assert.Equal(t, tc.expect, data)
126-
assert.False(t, body.IsEmpty())
127-
})
128-
}
94+
tt := []struct {
95+
name string
96+
rawBody string
97+
expect []byte
98+
}{{
99+
name: "image base64",
100+
rawBody: util.ImageBase64Prefix + defaultBase64Text,
101+
expect: []byte(defaultPlainText),
102+
}, {
103+
name: "pdf",
104+
rawBody: util.PDFBase64Prefix + defaultBase64Text,
105+
expect: []byte(defaultPlainText),
106+
}, {
107+
name: "zip",
108+
rawBody: util.ZIPBase64Prefix + defaultBase64Text,
109+
expect: []byte(defaultPlainText),
110+
}, {
111+
name: "binary",
112+
rawBody: util.BinaryBase64Prefix + defaultBase64Text,
113+
expect: []byte(defaultPlainText),
114+
}, {
115+
name: "raw",
116+
rawBody: defaultPlainText,
117+
expect: []byte(defaultPlainText),
118+
}}
119+
for _, tc := range tt {
120+
t.Run(tc.name, func(t *testing.T) {
121+
body := atesting.RequestBody{
122+
Value: tc.rawBody,
123+
}
124+
data := body.Bytes()
125+
assert.Equal(t, tc.expect, data)
126+
assert.False(t, body.IsEmpty())
127+
})
128+
}
129129
}

0 commit comments

Comments
 (0)