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


Golang testtool.TestEqual函数代码示例

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


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


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