Skip to content

Commit

Permalink
[kit] fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsannm committed Nov 22, 2023
1 parent b2c7244 commit 2f77630
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions kit/stub/stub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,34 @@ var _ = Describe("Stub Basic Functionality", func() {
Expect(httpCtx.Err()).To(BeNil())
})
})

var _ = Describe("Stub from URL", func() {
ctx := context.Background()

It("should unmarshal response from json", func() {
httpCtx, err := stub.HTTP("https://ipinfo.io/json?someKey=someValue")
Expect(err).To(BeNil())
httpCtx.
SetMethod(http.MethodGet).
DefaultResponseHandler(
func(_ context.Context, r stub.RESTResponse) *stub.Error {
switch r.StatusCode() {
case http.StatusOK:
v := &ipInfoResponse{}
Expect(json.Unmarshal(r.GetBody(), v)).To(Succeed())
Expect(v.Readme).To(Not(BeEmpty()))
Expect(v.IP).To(Not(BeEmpty()))
default:
Skip("we got error from ipinfo.io")
}

return nil
},
).
SetHeader("SomeKey", "SomeValue").
Run(ctx)
defer httpCtx.Release()

Expect(httpCtx.Err()).To(BeNil())
})
})
2 changes: 1 addition & 1 deletion kit/stub/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = DescribeTable(
Expect(stub.FillParams(in, f)).To(Equal(out))
},
Entry("",
"/some/{p1}/:p2?something={p3}&boolean",
"/some/{p1}/{p2}?something={p3}&boolean",
"/some/value1/value2?something=value3&boolean",
keyValues,
),
Expand Down

0 comments on commit 2f77630

Please sign in to comment.