Exemple #1
0
func Test_Request_URL_Params(t *testing.T) {
	r := require.New(t)
	w := willy.New(App())

	req := w.Request("/foo?a=%s&b=%s", "A", "B")
	r.Equal("/foo?a=A&b=B", req.URL)
}
Exemple #2
0
func Test_Request_Copies_Headers(t *testing.T) {
	r := require.New(t)
	w := willy.New(App())
	w.Headers["foo"] = "bar"

	req := w.Request("/")
	r.Equal("bar", req.Headers["foo"])
}
Exemple #3
0
func Test_Put_Struct_Pointer(t *testing.T) {
	r := require.New(t)
	w := willy.New(App())

	req := w.Request("/put")
	res := req.Put(&User{Name: "Mark"})
	r.Contains(res.Body.String(), "METHOD:PUT")
	r.Contains(res.Body.String(), "NAME:Mark")
}
Exemple #4
0
func Test_Post_Struct(t *testing.T) {
	r := require.New(t)
	w := willy.New(App())

	req := w.Request("/post")
	res := req.Post(User{Name: "Mark"})
	r.Contains(res.Body.String(), "METHOD:POST")
	r.Contains(res.Body.String(), "NAME:Mark")
}
Exemple #5
0
func Test_JSON_Headers_Dont_Overwrite_App_Headers(t *testing.T) {
	r := require.New(t)
	w := willy.New(JSONApp())
	w.Headers["foo"] = "bar"

	req := w.JSON("/")
	req.Headers["foo"] = "baz"
	r.Equal("baz", req.Headers["foo"])
	r.Equal("bar", w.Headers["foo"])
}
Exemple #6
0
func Test_Sessions(t *testing.T) {
	r := require.New(t)
	w := willy.New(App())

	res := w.Request("/sessions/get").Get()
	r.NotContains(res.Body.String(), "mark")
	w.Request("/sessions/set").Post(User{Name: "mark"})
	res = w.Request("/sessions/get").Get()
	r.Contains(res.Body.String(), "mark")
}
Exemple #7
0
func Test_Put_Values(t *testing.T) {
	r := require.New(t)
	w := willy.New(App())

	req := w.Request("/put")
	vals := url.Values{}
	vals.Add("name", "Mark")
	res := req.Put(vals)
	r.Contains(res.Body.String(), "METHOD:PUT")
	r.Contains(res.Body.String(), "NAME:Mark")
}
Exemple #8
0
func Test_Delete(t *testing.T) {
	r := require.New(t)
	w := willy.New(App())

	req := w.Request("/delete")
	r.Equal("/delete", req.URL)

	res := req.Delete()
	r.Contains(res.Body.String(), "METHOD:DELETE")
	r.Contains(res.Body.String(), "Goodbye")
}
Exemple #9
0
func Test_JSON_Put_Struct_Pointer(t *testing.T) {
	r := require.New(t)
	w := willy.New(JSONApp())

	req := w.JSON("/put")
	res := req.Put(&User{Name: "Mark"})

	jb := &jBody{}
	res.Bind(jb)
	r.Equal("PUT", jb.Method)
	r.Equal("Mark", jb.Name)
}
Exemple #10
0
func Test_JSON_Post_Struct(t *testing.T) {
	r := require.New(t)
	w := willy.New(JSONApp())

	req := w.JSON("/post")
	res := req.Post(User{Name: "Mark"})

	jb := &jBody{}
	res.Bind(jb)
	r.Equal("POST", jb.Method)
	r.Equal("Mark", jb.Name)
}
Exemple #11
0
func Test_Get(t *testing.T) {
	r := require.New(t)
	w := willy.New(App())

	req := w.Request("/get")
	r.Equal("/get", req.URL)

	res := req.Get()
	r.Equal(201, res.Code)
	r.Contains(res.Body.String(), "METHOD:GET")
	r.Contains(res.Body.String(), "Hello from Get!")
}
Exemple #12
0
func Test_JSON_Delete(t *testing.T) {
	r := require.New(t)
	w := willy.New(JSONApp())

	req := w.JSON("/delete")
	r.Equal("/delete", req.URL)

	res := req.Delete()
	jb := &jBody{}
	res.Bind(jb)
	r.Equal("DELETE", jb.Method)
	r.Equal("Goodbye", jb.Message)
}
Exemple #13
0
func Test_JSON_Get(t *testing.T) {
	r := require.New(t)
	w := willy.New(JSONApp())

	req := w.JSON("/get")
	r.Equal("/get", req.URL)

	res := req.Get()
	r.Equal(201, res.Code)
	jb := &jBody{}
	res.Bind(jb)
	r.Equal("GET", jb.Method)
	r.Equal("Hello from Get!", jb.Message)
}