Beispiel #1
0
// assertBookmarks tests the given bookmark jar.
func assertBookmarks(b BookmarksJar) {
	err := b.Save("test1", "http://localhost")
	ut.AssertNil(err)
	err = b.Save("test2", "http://127.0.0.1")
	ut.AssertNil(err)
	err = b.Save("test1", "http://localhost")
	ut.AssertNotNil(err)

	url, err := b.Read("test1")
	ut.AssertNil(err)
	ut.AssertEquals("http://localhost", url)
	url, err = b.Read("test2")
	ut.AssertEquals("http://127.0.0.1", url)
	url, err = b.Read("test3")
	ut.AssertNotNil(err)

	r := b.Remove("test2")
	ut.AssertTrue(r)
	r = b.Remove("test3")
	ut.AssertFalse(r)

	r = b.Has("test1")
	ut.AssertTrue(r)
	r = b.Has("test4")
	ut.AssertFalse(r)
}
Beispiel #2
0
func TestBrowserForm2(t *testing.T) {
	ut.Run(t)
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.Method == "GET" {
			fmt.Fprint(w, htmlForm2)
		} else {
			r.ParseForm()
			fmt.Fprint(w, r.Form.Encode())
		}
	}))
	defer ts.Close()

	bow := &Browser{}
	bow.headers = make(http.Header, 10)
	bow.history = jar.NewMemoryHistory()

	err := bow.Open(ts.URL)
	ut.AssertNil(err)

	f, err := bow.Form("[name='default']")
	ut.AssertNil(err)

	err = f.Input("age", "54")
	ut.AssertNil(err)
	err = f.Input("agee", "54")
	ut.AssertNotNil(err)

	err = f.CheckBox("music", []string{"rock", "fusion"})
	ut.AssertNil(err)

	err = f.CheckBox("music2", []string{"rock", "fusion"})
	ut.AssertNotNil(err)

	err = f.Click("submit2")

	ut.AssertNil(err)
	ut.AssertContains("company=none", bow.Body())
	ut.AssertContains("age=54", bow.Body())
	ut.AssertContains("gender=male", bow.Body())

	ut.AssertFalse(strings.Contains(bow.Body(), "music=jazz"))
	ut.AssertContains("music=rock", bow.Body())
	ut.AssertContains("music=fusion", bow.Body())

	ut.AssertContains("hobby=Dance", bow.Body())
	ut.AssertContains("city=NY", bow.Body())
	ut.AssertContains("submit2=submitted2", bow.Body())
}
Beispiel #3
0
func TestBrowserForm2(t *testing.T) {
	ts := setupTestServer(htmlForm2, t)
	defer ts.Close()

	bow := &Browser{}
	bow.headers = make(http.Header, 10)
	bow.history = jar.NewMemoryHistory()

	err := bow.Open(ts.URL)
	ut.AssertNil(err)

	f, err := bow.Form("[name='default']")
	ut.AssertNil(err)

	err = f.Input("age", "54")
	ut.AssertNil(err)
	err = f.Input("agee", "54")
	ut.AssertNotNil(err)

	err = f.CheckBox("music", []string{"rock", "fusion"})
	ut.AssertNil(err)

	err = f.CheckBox("music2", []string{"rock", "fusion"})
	ut.AssertNotNil(err)

	err = f.Click("submit2")

	ut.AssertNil(err)
	ut.AssertContains("company=none", bow.Body())
	ut.AssertContains("age=54", bow.Body())
	ut.AssertContains("gender=male", bow.Body())

	ut.AssertFalse(strings.Contains(bow.Body(), "music=jazz"))
	ut.AssertContains("music=rock", bow.Body())
	ut.AssertContains("music=fusion", bow.Body())

	ut.AssertContains("hobby=Dance", bow.Body())
	ut.AssertContains("city=NY", bow.Body())
	ut.AssertContains("submit2=submitted2", bow.Body())
}
Beispiel #4
0
func TestHead(t *testing.T) {
	ut.Run(t)
	var r *http.Request

	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		r = req
	}))
	defer ts.Close()

	bow := NewBrowser()

	err := bow.Head(ts.URL + "/page1")
	ut.AssertNil(err)
	ut.AssertNotNil(r)
}