本文整理匯總了Golang中github.com/headzoo/ut.AssertEquals函數的典型用法代碼示例。如果您正苦於以下問題:Golang AssertEquals函數的具體用法?Golang AssertEquals怎麽用?Golang AssertEquals使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AssertEquals函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestGet
func TestGet(t *testing.T) {
ut.Run(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if req.URL.Path == "/page1" {
fmt.Fprint(w, htmlPage1)
} else if req.URL.Path == "/page2" {
fmt.Fprint(w, htmlPage2)
}
}))
defer ts.Close()
bow := NewBrowser()
err := bow.Open(ts.URL + "/page1")
ut.AssertNil(err)
ut.AssertEquals("Surf Page 1", bow.Title())
ut.AssertContains("<p>Hello, Surf!</p>", bow.Body())
err = bow.Open(ts.URL + "/page2")
ut.AssertNil(err)
ut.AssertEquals("Surf Page 2", bow.Title())
ok := bow.Back()
ut.AssertTrue(ok)
ut.AssertEquals("Surf Page 1", bow.Title())
ok = bow.Back()
ut.AssertFalse(ok)
ut.AssertEquals("Surf Page 1", bow.Title())
}
示例2: TestImages
func TestImages(t *testing.T) {
ut.Run(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprint(w, htmlPage1)
}))
defer ts.Close()
bow := NewBrowser()
err := bow.Open(ts.URL)
ut.AssertNil(err)
images := bow.Images()
ut.AssertEquals(2, len(images))
ut.AssertEquals("imgur-image", images[0].ID)
ut.AssertEquals("http://i.imgur.com/HW4bJtY.jpg", images[0].URL.String())
ut.AssertEquals("", images[0].Alt)
ut.AssertEquals("It's a...", images[0].Title)
ut.AssertEquals("", images[1].ID)
ut.AssertEquals(ts.URL+"/Cxagv.jpg", images[1].URL.String())
ut.AssertEquals("A picture", images[1].Alt)
ut.AssertEquals("", images[1].Title)
buff := &bytes.Buffer{}
l, err := images[0].Download(buff)
ut.AssertNil(err)
ut.AssertGreaterThan(0, buff.Len())
ut.AssertEquals(int(l), buff.Len())
}
示例3: TestBrowserForm
func TestBrowserForm(t *testing.T) {
ts := setupTestServer(htmlForm, 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)
v, ok := f.Field("age")
ut.AssertTrue(ok)
ut.AssertEquals("", v)
v, ok = f.Field("ageage")
ut.AssertFalse(ok)
ut.AssertEquals("", v)
f.Input("age", "55")
v, ok = f.Field("age")
ut.AssertTrue(ok)
ut.AssertEquals("55", v)
f.Input("gender", "male")
err = f.Click("submit2")
ut.AssertNil(err)
ut.AssertContains("age=55", bow.Body())
ut.AssertContains("gender=male", bow.Body())
ut.AssertContains("submit2=submitted2", bow.Body())
}
示例4: assertBookmarks
// 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)
}
示例5: TestStylesheets
func TestStylesheets(t *testing.T) {
ut.Run(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprint(w, htmlPage1)
}))
defer ts.Close()
bow := NewBrowser()
err := bow.Open(ts.URL)
ut.AssertNil(err)
stylesheets := bow.Stylesheets()
ut.AssertEquals(2, len(stylesheets))
ut.AssertEquals("http://godoc.org/-/site.css", stylesheets[0].URL.String())
ut.AssertEquals("all", stylesheets[0].Media)
ut.AssertEquals("text/css", stylesheets[0].Type)
ut.AssertEquals(ts.URL+"/print.css", stylesheets[1].URL.String())
ut.AssertEquals("print", stylesheets[1].Media)
ut.AssertEquals("text/css", stylesheets[1].Type)
buff := &bytes.Buffer{}
l, err := stylesheets[0].Download(buff)
ut.AssertNil(err)
ut.AssertGreaterThan(0, buff.Len())
ut.AssertEquals(int(l), buff.Len())
}
示例6: TestBrowserForm
func TestBrowserForm(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, htmlForm)
} 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)
v, ok := f.Field("age")
ut.AssertTrue(ok)
ut.AssertEquals("", v)
v, ok = f.Field("ageage")
ut.AssertFalse(ok)
ut.AssertEquals("", v)
f.Input("age", "55")
v, ok = f.Field("age")
ut.AssertTrue(ok)
ut.AssertEquals("55", v)
f.Input("gender", "male")
err = f.Click("submit2")
ut.AssertNil(err)
ut.AssertContains("age=55", bow.Body())
ut.AssertContains("gender=male", bow.Body())
ut.AssertContains("submit2=submitted2", bow.Body())
}
示例7: TestDownload
func TestDownload(t *testing.T) {
ut.Run(t)
out := &bytes.Buffer{}
u, _ := url.Parse("http://i.imgur.com/HW4bJtY.jpg")
asset := NewImageAsset(u, "", "", "")
l, err := DownloadAsset(asset, out)
ut.AssertNil(err)
ut.AssertGreaterThan(0, int(l))
ut.AssertEquals(int(l), out.Len())
}
示例8: TestBookmarks
func TestBookmarks(t *testing.T) {
ut.Run(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprint(w, htmlPage1)
}))
defer ts.Close()
bookmarks := jar.NewMemoryBookmarks()
bow := NewBrowser()
bow.SetBookmarksJar(bookmarks)
bookmarks.Save("test1", ts.URL)
bow.OpenBookmark("test1")
ut.AssertEquals("Surf Page 1", bow.Title())
ut.AssertContains("<p>Hello, Surf!</p>", bow.Body())
err := bow.Bookmark("test2")
ut.AssertNil(err)
bow.OpenBookmark("test2")
ut.AssertEquals("Surf Page 1", bow.Title())
}
示例9: TestUserAgent
func TestUserAgent(t *testing.T) {
ut.Run(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
fmt.Fprint(w, req.UserAgent())
}))
defer ts.Close()
bow := NewBrowser()
bow.SetUserAgent("Testing/1.0")
err := bow.Open(ts.URL)
ut.AssertNil(err)
ut.AssertEquals("Testing/1.0", bow.Body())
}
示例10: TestDownloadAsync
func TestDownloadAsync(t *testing.T) {
ut.Run(t)
ch := make(AsyncDownloadChannel, 1)
u1, _ := url.Parse("http://i.imgur.com/HW4bJtY.jpg")
u2, _ := url.Parse("http://i.imgur.com/HkPOzEH.jpg")
asset1 := NewImageAsset(u1, "", "", "")
asset2 := NewImageAsset(u2, "", "", "")
out1 := &bytes.Buffer{}
out2 := &bytes.Buffer{}
queue := 2
DownloadAssetAsync(asset1, out1, ch)
DownloadAssetAsync(asset2, out2, ch)
for {
select {
case result := <-ch:
ut.AssertGreaterThan(0, int(result.Size))
if result.Asset == asset1 {
ut.AssertEquals(int(result.Size), out1.Len())
} else if result.Asset == asset2 {
ut.AssertEquals(int(result.Size), out2.Len())
} else {
t.Failed()
}
queue--
if queue == 0 {
goto COMPLETE
}
}
}
COMPLETE:
close(ch)
ut.AssertEquals(0, queue)
}
示例11: TestDownloadContentType
func TestDownloadContentType(t *testing.T) {
ut.Run(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
b := bytes.NewBufferString("Hello")
fmt.Fprint(w, b)
}))
defer ts.Close()
bow := NewBrowser()
bow.Open(ts.URL)
buff := &bytes.Buffer{}
bow.Download(buff)
ut.AssertEquals("Hello", buff.String())
}
示例12: TestDownload
func TestDownload(t *testing.T) {
ut.Run(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
fmt.Fprint(w, req.UserAgent())
}))
defer ts.Close()
bow := NewBrowser()
bow.Open(ts.URL)
buff := &bytes.Buffer{}
l, err := bow.Download(buff)
ut.AssertNil(err)
ut.AssertGreaterThan(0, int(l))
ut.AssertEquals(int(l), buff.Len())
}
示例13: TestPost
func TestPost(t *testing.T) {
ut.Run(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if req.Method == "POST" {
w.WriteHeader(200)
w.Write([]byte("OK"))
} else {
w.WriteHeader(500)
w.Write([]byte("ERROR"))
}
}))
defer ts.Close()
bow := NewBrowser()
bow.Post(ts.URL, "application/x-www-form-urlencoded", nil)
ut.AssertEquals(200, bow.StatusCode())
}
示例14: TestMemoryHistory
func TestMemoryHistory(t *testing.T) {
ut.Run(t)
stack := NewMemoryHistory()
page1 := &State{}
stack.Push(page1)
ut.AssertEquals(1, stack.Len())
ut.AssertEquals(page1, stack.Top())
page2 := &State{}
stack.Push(page2)
ut.AssertEquals(2, stack.Len())
ut.AssertEquals(page2, stack.Top())
page := stack.Pop()
ut.AssertEquals(page, page2)
ut.AssertEquals(1, stack.Len())
ut.AssertEquals(page1, stack.Top())
page = stack.Pop()
ut.AssertEquals(page, page1)
ut.AssertEquals(0, stack.Len())
}
示例15: TestLinks
func TestLinks(t *testing.T) {
ut.Run(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprint(w, htmlPage1)
}))
defer ts.Close()
bow := NewBrowser()
err := bow.Open(ts.URL)
ut.AssertNil(err)
links := bow.Links()
ut.AssertEquals(2, len(links))
ut.AssertEquals("", links[0].ID)
ut.AssertEquals(ts.URL+"/page2", links[0].URL.String())
ut.AssertEquals("click", links[0].Text)
ut.AssertEquals("page3", links[1].ID)
ut.AssertEquals(ts.URL+"/page3", links[1].URL.String())
ut.AssertEquals("no clicking", links[1].Text)
}