当前位置: 首页>>代码示例>>Golang>>正文


Golang ut.Run函数代码示例

本文整理汇总了Golang中github.com/headzoo/ut.Run函数的典型用法代码示例。如果您正苦于以下问题:Golang Run函数的具体用法?Golang Run怎么用?Golang Run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Run函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestScripts

func TestScripts(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)

	scripts := bow.Scripts()
	ut.AssertEquals(2, len(scripts))
	ut.AssertEquals("http://godoc.org/-/site.js", scripts[0].URL.String())
	ut.AssertEquals("text/javascript", scripts[0].Type)

	ut.AssertEquals(ts.URL+"/jquery.min.js", scripts[1].URL.String())
	ut.AssertEquals("text/javascript", scripts[1].Type)

	buff := &bytes.Buffer{}
	l, err := scripts[0].Download(buff)
	ut.AssertNil(err)
	ut.AssertGreaterThan(0, buff.Len())
	ut.AssertEquals(int(l), buff.Len())
}
开发者ID:headzoo,项目名称:surf,代码行数:25,代码来源:surf_test.go

示例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())
}
开发者ID:headzoo,项目名称:surf,代码行数:29,代码来源:surf_test.go

示例3: 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)

	f.Input("age", "55")
	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())
}
开发者ID:jabbahotep,项目名称:surf,代码行数:30,代码来源:form_test.go

示例4: 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())
}
开发者ID:headzoo,项目名称:surf,代码行数:30,代码来源:surf_test.go

示例5: TestFileExists

func TestFileExists(t *testing.T) {
	ut.Run(t)

	ex := FileExists("./util_test.go")
	ut.AssertTrue(ex)

	ex = FileExists("./util.txt")
	ut.AssertFalse(ex)
}
开发者ID:headzoo,项目名称:surf,代码行数:9,代码来源:util_test.go

示例6: TestFileBookmarks

func TestFileBookmarks(t *testing.T) {
	ut.Run(t)

	b, err := NewFileBookmarks("./bookmarks.json")
	ut.AssertNil(err)
	defer func() {
		err = os.Remove("./bookmarks.json")
	}()
	assertBookmarks(b)
}
开发者ID:headzoo,项目名称:surf,代码行数:10,代码来源:bookmarks_test.go

示例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())
}
开发者ID:headzoo,项目名称:surf,代码行数:11,代码来源:assets_test.go

示例8: setupTestServer

func setupTestServer(html string, t *testing.T) *httptest.Server {
	ut.Run(t)
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.Method == "GET" {
			fmt.Fprint(w, html)
		} else {
			r.ParseForm()
			fmt.Fprint(w, r.Form.Encode())
		}
	}))

	return ts
}
开发者ID:joshuamorris3,项目名称:surf,代码行数:13,代码来源:form_test.go

示例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())
}
开发者ID:headzoo,项目名称:surf,代码行数:13,代码来源:surf_test.go

示例10: TestHeadersBug19

// TestHeadersSet
// See: https://github.com/headzoo/surf/pull/19
func TestHeadersBug19(t *testing.T) {
	ut.Run(t)
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		fmt.Fprint(w, req.Header.Get("X-Testing"))
	}))
	defer ts.Close()

	bow := NewBrowser()
	bow.AddRequestHeader("X-Testing", "Testing-1")
	bow.AddRequestHeader("X-Testing", "Testing-2")
	err := bow.Open(ts.URL)
	ut.AssertNil(err)
	ut.AssertContains("Testing-2", bow.Body())
}
开发者ID:headzoo,项目名称:surf,代码行数:16,代码来源:surf_test.go

示例11: TestHead

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)
}
开发者ID:headzoo,项目名称:surf,代码行数:15,代码来源:surf_test.go

示例12: 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())
}
开发者ID:headzoo,项目名称:surf,代码行数:15,代码来源:surf_test.go

示例13: TestBrowserForm2

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())
}
开发者ID:haruyama,项目名称:surf,代码行数:48,代码来源:form_test.go

示例14: 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())
}
开发者ID:headzoo,项目名称:surf,代码行数:16,代码来源:surf_test.go

示例15: 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())
}
开发者ID:headzoo,项目名称:surf,代码行数:17,代码来源:surf_test.go


注:本文中的github.com/headzoo/ut.Run函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。