httpexpect
httpexpect copied to clipboard
Add environment in expect
Add environment in Expect
to manipulate test data.
This pr is a proposal for environment :) For examples, i want to use a value from previous test like below
func TestIT(t *testing.T) {
e := httpexpect.New(t, "http://localhost:8080")
t.Run("/users", func(t *testing.T) {
obj := e.GET("/users").
Expect().
Status(http.StatusOK).JSON().Object()
userID := obj.Path("$.users[1].id").String().Raw()
e.Env.Put("user1.id", userID)
})
t.Run("/user/{userId}", func(t *testing.T) {
// use a user's id from above tests.
userID, err := e.Env.GetString("user1.id")
assert.NoError(t, err)
e.GET("/user/{userId}").
WithPath("userId", userID)
Expect().
Status(http.StatusOK)
})
}
If u agree with this concept, i will implement more such as int slice types with tests. Thanks for providing a good test library!