• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang testtool.TestEqual函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestSubtract

func TestSubtract(t *testing.T) {
	ipr, err := ParseIPRange("192.168.1.10-19")
	tt.TestExpectSuccess(t, err)
	alloc := NewAllocator(ipr)
	tt.TestEqual(t, alloc.remaining, int64(10))

	// create a smaller range within the same one
	ipr2, err := ParseIPRange("192.168.1.10-14")
	tt.TestExpectSuccess(t, err)

	// subtract it
	alloc.Subtract(ipr2)

	// validate it
	tt.TestEqual(t, alloc.remaining, int64(5))
	tt.TestEqual(t, len(alloc.reserved), 5)

	// consume everything and ensure we don't get an IP in the second range.
	for {
		if alloc.Remaining() == 0 {
			break
		}

		ip := alloc.Allocate()
		tt.TestNotEqual(t, ip, nil)
		tt.TestEqual(t, ipr2.Contains(ip), false)
	}
}
开发者ID:wallyqs,项目名称:util,代码行数:28,代码来源:allocator_test.go


示例2: TestReadInt64

func TestReadInt64(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	f := tt.WriteTempFile(t, "foo\nbar")

	_, err := ReadInt64(f)
	tt.TestExpectError(t, err)

	f = tt.WriteTempFile(t, "123\n456")

	v, err := ReadInt64(f)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, v, int64(123))

	f = tt.WriteTempFile(t, "123456789")
	v, err = ReadInt64(f)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, v, int64(123456789))

	maxInt64 := fmt.Sprintf("%d", int64(1<<63-1))
	f = tt.WriteTempFile(t, maxInt64)

	v, err = ReadInt64(f)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, v, int64(1<<63-1))

	maxInt64WithExtra := fmt.Sprintf("%d666", int64(1<<63-1))
	f = tt.WriteTempFile(t, maxInt64WithExtra)

	v, err = ReadInt64(f)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, v, int64(1<<63-1))
}
开发者ID:wallyqs,项目名称:util,代码行数:34,代码来源:parser_test.go


示例3: TestNewRequest

func TestNewRequest(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	// create a test server
	method, path, body := "", "", ""
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		method = req.Method
		path = req.URL.Path

		defer req.Body.Close()
		b, err := ioutil.ReadAll(req.Body)
		if err != nil {
			t.Errorf("Error reading request: %v", err)
			w.WriteHeader(500)
			return
		}
		body = string(b)
		w.WriteHeader(200)
	}))
	defer server.Close()

	client, err := New(server.URL)
	tt.TestExpectSuccess(t, err)
	req := client.NewRequest("POST", "/blobs", "text/plain", strings.NewReader("I am a giant blob of bytes!"))
	err = client.Result(req, nil)
	tt.TestExpectSuccess(t, err)

	// Verify request as received by server
	tt.TestEqual(t, method, "POST")
	tt.TestEqual(t, path, "/blobs")
	tt.TestEqual(t, body, "I am a giant blob of bytes!")
}
开发者ID:wallyqs,项目名称:util,代码行数:33,代码来源:restclient_test.go


示例4: TestRelease

func TestRelease(t *testing.T) {
	ipr, err := ParseIPRange("192.168.1.10-19")
	tt.TestExpectSuccess(t, err)
	alloc := NewAllocator(ipr)

	// test releasing when empty
	alloc.Release(net.ParseIP("192.168.1.11"))
	tt.TestEqual(t, alloc.remaining, int64(10))

	// consume everything
	for {
		if alloc.Remaining() == 0 {
			break
		}
		ip := alloc.Allocate()
		tt.TestNotEqual(t, ip, nil)
	}

	// release an IP
	tt.TestEqual(t, alloc.remaining, int64(0))
	alloc.Release(net.ParseIP("192.168.1.11"))
	tt.TestEqual(t, alloc.remaining, int64(1))

	// allocate one more and should get that one
	tt.TestEqual(t, alloc.Allocate().String(), "192.168.1.11")
	tt.TestEqual(t, alloc.remaining, int64(0))
}
开发者ID:wallyqs,项目名称:util,代码行数:27,代码来源:allocator_test.go


示例5: TestErrorResponseNoBody

func TestErrorResponseNoBody(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	// create a test server
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		w.Header().Set("Content-Type", "text/plain")
		w.WriteHeader(500)
	}))
	defer server.Close()

	client, err := New(server.URL)
	tt.TestExpectSuccess(t, err)
	req := client.NewFormRequest("GET", "/", nil)
	resp, err := client.Do(req)
	tt.TestExpectError(t, err)

	rerr, ok := err.(*RestError)
	tt.TestEqual(t, ok, true, "Error should be of type *RestError")
	tt.TestEqual(t, rerr.Error(), "error in response: 500 Internal Server Error")

	body, err := ioutil.ReadAll(resp.Body)
	defer resp.Body.Close()
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, string(body), "")
}
开发者ID:wallyqs,项目名称:util,代码行数:26,代码来源:restclient_test.go


示例6: TestErrorResult

func TestErrorResult(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	// create a test server
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		w.Header().Set("Content-Type", "text/plain")
		w.WriteHeader(500)
		io.WriteString(w, "Didn't work")
	}))
	defer server.Close()

	client, err := New(server.URL)
	tt.TestExpectSuccess(t, err)
	req := client.NewFormRequest("GET", "/", nil)
	err = client.Result(req, nil)
	tt.TestExpectError(t, err)

	rerr, ok := err.(*RestError)
	tt.TestEqual(t, ok, true, "Error should be of type *RestError")
	tt.TestEqual(t, rerr.Error(), "error in response: 500 Internal Server Error - Didn't work")
	tt.TestEqual(t, rerr.Body(), "Didn't work")

	rerr2 := new(RestError)
	rerr2.err = fmt.Errorf("foo bar baz wibble")
	tt.TestEqual(t, rerr2.Error(), "foo bar baz wibble")

	rerr2 = new(RestError)
	rerr2.Resp = &http.Response{
		StatusCode: 404,
	}
	rerr2.err = fmt.Errorf("foo bar baz wibble")
	tt.TestEqual(t, rerr2.Error(), "foo bar baz wibble")
}
开发者ID:wallyqs,项目名称:util,代码行数:34,代码来源:restclient_test.go


示例7: TestDeepMergeChildrenPropagateToSource

func TestDeepMergeChildrenPropagateToSource(t *testing.T) {
	dst := make(map[string]interface{})
	src1 := map[string]interface{}{
		"foobar": map[string]interface{}{
			"one":   float64(1),
			"three": float64(3),
		},
	}
	src2 := map[string]interface{}{
		"foobar": map[string]interface{}{
			"two":  "2",
			"four": float64(4),
		},
	}
	expected := map[string]interface{}{
		"foobar": map[string]interface{}{
			"one":   float64(1),
			"two":   "2",
			"three": float64(3),
			"four":  float64(4),
		},
	}
	expectedSrc1 := map[string]interface{}{
		"foobar": map[string]interface{}{
			"one":   float64(1),
			"three": float64(3),
		},
	}
	tt.TestExpectSuccess(t, Merge(dst, src1))
	tt.TestExpectSuccess(t, Merge(dst, src2))
	tt.TestEqual(t, dst, expected)
	tt.TestEqual(t, src1, expectedSrc1)
}
开发者ID:wallyqs,项目名称:util,代码行数:33,代码来源:merge_test.go


示例8: TestNewAllocator

func TestNewAllocator(t *testing.T) {
	ipr, err := ParseIPRange("192.168.1.10-19")
	tt.TestExpectSuccess(t, err)

	alloc := NewAllocator(ipr)
	tt.TestEqual(t, alloc.size, int64(10))
	tt.TestEqual(t, alloc.remaining, int64(10))
}
开发者ID:wallyqs,项目名称:util,代码行数:8,代码来源:allocator_test.go


示例9: TestReserveOutOfRange

func TestReserveOutOfRange(t *testing.T) {
	ipr, err := ParseIPRange("192.168.1.10-19")
	tt.TestExpectSuccess(t, err)
	alloc := NewAllocator(ipr)

	// reserve an IP
	reservedIP := net.ParseIP("10.0.0.1")
	alloc.Reserve(reservedIP)
	tt.TestEqual(t, alloc.remaining, int64(10))
	tt.TestEqual(t, len(alloc.reserved), 0)
}
开发者ID:wallyqs,项目名称:util,代码行数:11,代码来源:allocator_test.go


示例10: TestHelper_newRequestWithParams

func TestHelper_newRequestWithParams(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	client, err := New("http://example.com/resources")
	tt.TestExpectSuccess(t, err)
	req := client.newRequest(GET, "/excellence?yeah=stuff&more=params")

	tt.TestEqual(t, req.Method, GET)
	tt.TestEqual(t, req.URL.String(), "http://example.com/resources/excellence?yeah=stuff&more=params")
	tt.TestEqual(t, req.Headers, http.Header(map[string][]string{}))
}
开发者ID:wallyqs,项目名称:util,代码行数:12,代码来源:restclient_test.go


示例11: TestGetImageTags

func TestGetImageTags(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	img, statusCode, err := GetImage("foo/bar", "")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, statusCode, 200)

	tags := img.Tags()
	sort.Strings(tags)
	tt.TestEqual(t, tags, []string{"base", "latest"})
}
开发者ID:wallyqs,项目名称:util,代码行数:12,代码来源:registry_test.go


示例12: TestDeepMergeHandlesNilDestination

func TestDeepMergeHandlesNilDestination(t *testing.T) {
	var dst map[string]interface{}
	src := map[string]interface{}{
		"two":  "2",
		"four": float64(4),
	}
	err := Merge(dst, src)
	tt.TestExpectError(t, err)
	tt.TestEqual(t, err, NilDestinationError)
	dst = make(map[string]interface{})
	tt.TestExpectSuccess(t, Merge(dst, src))
	tt.TestEqual(t, dst, src)
}
开发者ID:wallyqs,项目名称:util,代码行数:13,代码来源:merge_test.go


示例13: TestAllocate

func TestAllocate(t *testing.T) {
	ipr, err := ParseIPRange("192.168.1.10-19")
	tt.TestExpectSuccess(t, err)
	alloc := NewAllocator(ipr)

	// get the first one
	ip := alloc.Allocate()
	tt.TestEqual(t, ipr.Contains(ip), true)
	tt.TestEqual(t, alloc.Remaining(), int64(9))

	// consume the others
	for i := 0; i < 8; i++ {
		ip = alloc.Allocate()
		tt.TestEqual(t, ipr.Contains(ip), true, fmt.Sprintf("%s was not within the range", ip.String()))
	}
	tt.TestEqual(t, alloc.Remaining(), int64(1))

	// last ip
	ip = alloc.Allocate()
	tt.TestEqual(t, ipr.Contains(ip), true)
	tt.TestEqual(t, alloc.Remaining(), int64(0))

	// no more left
	ip = alloc.Allocate()
	tt.TestEqual(t, ip, nil)
	tt.TestEqual(t, alloc.Remaining(), int64(0))
}
开发者ID:wallyqs,项目名称:util,代码行数:27,代码来源:allocator_test.go


示例14: TestGetImageMetadata

func TestGetImageMetadata(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	img, statusCode, err := GetImage("foo/bar", "")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, statusCode, 200)

	var m1 map[string]interface{}
	err = img.Metadata("tag2", &m1)
	tt.TestExpectError(t, err)
	tt.TestEqual(t, err.Error(), "can't find tag 'tag2' for image 'foo/bar'")

	var m2 map[string]interface{}
	err = img.Metadata("latest", &m2)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, len(m2), 2)
	tt.TestEqual(t, m2["id"], "deadbeef")
	tt.TestEqual(t, m2["k2"], "v2")

	var m3 map[string]interface{}
	err = img.Metadata("base", &m3)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, len(m3), 2)
	tt.TestEqual(t, m3["id"], "badcafe")
	tt.TestEqual(t, m3["k1"], "v1")
}
开发者ID:wallyqs,项目名称:util,代码行数:27,代码来源:registry_test.go


示例15: TestEmptyPostRequest

func TestEmptyPostRequest(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	// create a test server
	body := ""
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		defer req.Body.Close()
		b, err := ioutil.ReadAll(req.Body)
		if err != nil {
			t.Errorf("Error reading request: %v", err)
			w.WriteHeader(500)
			return
		}
		body = string(b)
		w.WriteHeader(200)
	}))
	defer server.Close()

	client, err := New(server.URL)
	tt.TestExpectSuccess(t, err)
	req := client.NewJsonRequest("POST", "/", nil)

	err = client.Result(req, nil)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, body, "")
}
开发者ID:wallyqs,项目名称:util,代码行数:27,代码来源:restclient_test.go


示例16: TestFormRequest

func TestFormRequest(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	// create a test server
	var form url.Values
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		if err := req.ParseForm(); err != nil {
			t.Errorf("Error reading request: %v", err)
			w.WriteHeader(500)
			return
		}
		form = req.Form
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(200)
		io.WriteString(w, `{"foo":"bar"}`)
	}))
	defer server.Close()

	client, err := New(server.URL)
	tt.TestExpectSuccess(t, err)
	req := client.NewFormRequest("POST", "/", map[string]string{"name": "Tim"})
	err = client.Result(req, nil)
	tt.TestExpectSuccess(t, err)

	// Verify form data as received by server
	tt.TestEqual(t, form.Get("name"), "Tim")
}
开发者ID:wallyqs,项目名称:util,代码行数:28,代码来源:restclient_test.go


示例17: TestClient_Exec

func TestClient_Exec(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	socketFile, l := createSocketServer(t)
	defer l.Close()

	var execContent string
	readChan := setupReadRequest(t, l, &execContent, "REQUEST OK\n")

	client := New(socketFile)
	err := client.Exec(
		[]string{"/sbin/init", "foo"}, []string{"FOO=bar"}, "/a", "/b", time.Second,
	)
	tt.TestExpectSuccess(t, err)

	select {
	case <-readChan:
	case <-time.After(time.Second):
		tt.Fatalf(t, "Expected to have read client response within 1 second")
	}

	expectedRequest := "1\n4\n1\n4\nEXEC2\n10\n/sbin/init3\nfoo1\n7\nFOO=bar2\n2\n/a2\n/b"
	tt.TestEqual(t, execContent, expectedRequest)
}
开发者ID:liyangdal,项目名称:kurma,代码行数:25,代码来源:client_test.go


示例18: TestEnvMapGetUnflattened

func TestEnvMapGetUnflattened(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	root := NewEnvMap()
	root.Set("VARIABLE", "foo bar $STR")
	root.Set("VAR1", "abc 123 $VAR2")
	root.Set("VAR2", "xyz")

	root.FlattenMap(false)
	envMap := root.Map()

	tt.TestEqual(t, envMap["VAR1"], "abc 123 $VAR2")
	tt.TestEqual(t, envMap["VAR2"], "xyz")
	tt.TestEqual(t, envMap["VARIABLE"], "foo bar $STR")
}
开发者ID:wallyqs,项目名称:util,代码行数:16,代码来源:envmap_test.go


示例19: TestClient_Start

func TestClient_Start(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	socketFile, l := createSocketServer(t)
	defer l.Close()

	var startContent string
	readChan := setupReadRequest(t, l, &startContent, "REQUEST OK\n")

	client := New(socketFile)
	err := client.Start(
		"echo", []string{"123"}, "dir", []string{"FOO=bar"},
		"/a", "/b", "123", "456", time.Second,
	)
	tt.TestExpectSuccess(t, err)

	select {
	case <-readChan:
	case <-time.After(time.Second):
		tt.Fatalf(t, "Expected to have read client response within 1 second")
	}

	expectedRequest := "1\n6\n2\n5\nSTART4\necho1\n3\n1231\n3\ndir1\n7\nFOO=bar2\n2\n/a2\n/b2\n3\n1233\n456"
	tt.TestEqual(t, startContent, expectedRequest)
}
开发者ID:liyangdal,项目名称:kurma,代码行数:26,代码来源:client_test.go


示例20: TestComputeHmacSha1

// Make sure that HMAC Sha1 is calculated correctly
func TestComputeHmacSha1(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	hmacSha1 := ComputeHmacSha1("message", "secret")
	tt.TestEqual(t, hmacSha1, "DK9kn+7klT2Hv5A6wRdsReAo3xY=")
}
开发者ID:wallyqs,项目名称:util,代码行数:8,代码来源:hmac_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang testtool.TestExpectSuccess函数代码示例发布时间:2022-05-24
下一篇:
Golang testtool.StartTest函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap