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


Golang testtool.TestExpectSuccess函数代码示例

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


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

示例1: TestIPRangeOverlap

func TestIPRangeOverlap(t *testing.T) {
	ipr1, err := ParseIPRange("192.168.1.1-100")
	tt.TestExpectSuccess(t, err)
	ipr2, err := ParseIPRange("192.168.1.101-200")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), false)

	ipr2, err = ParseIPRange("192.168.1.100-200")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), true)

	ipr2, err = ParseIPRange("192.168.1.50-55")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), true)

	ipr2, err = ParseIPRange("192.168.1.1")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), true)

	ipr1, err = ParseIPRange("192.168.1.200-210")
	tt.TestExpectSuccess(t, err)
	ipr2, err = ParseIPRange("192.168.1.100-150")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), false)

	ipr2, err = ParseIPRange("192.168.1.100-250")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), true)

	ipr1, err = ParseIPRange("192.168.1.1-255/24")
	tt.TestExpectSuccess(t, err)
	ipr2, err = ParseIPRange("192.168.0.1-3.255/22")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), true)
}
开发者ID:wallyqs,项目名称:util,代码行数:35,代码来源:iprange_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: 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

示例4: 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

示例5: 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

示例6: 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

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

示例8: 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

示例9: 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

示例10: createSocketServer

func createSocketServer(t *testing.T) (string, net.Listener) {
	socketFile := tt.TempFile(t)
	tt.TestExpectSuccess(t, os.Remove(socketFile))

	l, err := net.Listen("unix", socketFile)
	tt.TestExpectSuccess(t, err)

	return socketFile, l
}
开发者ID:liyangdal,项目名称:kurma,代码行数:9,代码来源:client_test.go

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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