Skip to content

Commit 6e646b3

Browse files
committed
test: add aksk usage
1 parent 8bf7744 commit 6e646b3

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

codecov.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
ignore:
22
- "**/*.gen.go"
3+
- "examples"

integrationtest/aksk_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,43 @@ func AkSkSpec(ctx context.Context, urlStr string) func(c convey.C) {
141141
convey.ShouldHaveLength(result.JSON200, 6)
142142
})
143143
})
144+
145+
c.Convey("aksk usage", func(c convey.C) {
146+
c.Convey("success", func(c convey.C) {
147+
aksk, err := createAksk(ctx, client)
148+
convey.So(err, convey.ShouldBeNil)
149+
150+
cli, err := api.NewClient(urlStr+apiimpl.APIV1Prefix, api.AkSkOption(aksk.AccessKey, aksk.SecretKey))
151+
convey.So(err, convey.ShouldBeNil)
152+
153+
resp, err := cli.GetUserInfo(ctx)
154+
convey.So(err, convey.ShouldBeNil)
155+
156+
user, err := api.ParseGetUserInfoResponse(resp)
157+
convey.So(err, convey.ShouldBeNil)
158+
convey.ShouldEqual(user.JSON200.Name, userName)
159+
})
160+
c.Convey("wrong sk", func(c convey.C) {
161+
aksk, err := createAksk(ctx, client)
162+
convey.So(err, convey.ShouldBeNil)
163+
164+
client, err := api.NewClient(urlStr+apiimpl.APIV1Prefix, api.AkSkOption(aksk.AccessKey, "fakesk"))
165+
convey.So(err, convey.ShouldBeNil)
166+
167+
resp, err := client.GetUserInfo(ctx)
168+
convey.So(err, convey.ShouldBeNil)
169+
convey.ShouldEqual(resp.StatusCode, http.StatusUnauthorized)
170+
})
171+
172+
c.Convey("ak not exit", func(c convey.C) {
173+
client, err := api.NewClient(urlStr+apiimpl.APIV1Prefix, api.AkSkOption("fakesk", "fakesk"))
174+
convey.So(err, convey.ShouldBeNil)
175+
176+
resp, err := client.GetUserInfo(ctx)
177+
convey.So(err, convey.ShouldBeNil)
178+
convey.ShouldEqual(resp.StatusCode, http.StatusUnauthorized)
179+
})
180+
})
144181
}
145182
}
146183

0 commit comments

Comments
 (0)