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


Golang testtool.StartTest函数代码示例

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


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

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

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

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

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

示例5: TestEnvMap

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

	expected := []string{
		"START_COMMAND=XYZ",
		"TEST_CROSSREF1=cross_pkg2",
		"TEST_CROSSREF2=cross_pkg1",
		"TEST_CROSSREF_VAL1=cross_pkg1",
		"TEST_CROSSREF_VAL2=cross_pkg2",
		"TEST_ENV_VARIABLE=TEST_ENV_CONTENT",
		"TEST_MERGE_UNDEFINED=undef:",
		"TEST_MERGE_VARIABLE=pkg2:pkg1:",
		"TEST_OVERRIDE_VARIABLE=pkg2",
	}

	root := NewEnvMap()
	root.Set("TEST_ENV_VARIABLE", "TEST_ENV_CONTENT")
	root.Set("TEST_MERGE_VARIABLE", "pkg1:$TEST_MERGE_VARIABLE")
	root.Set("TEST_MERGE_UNDEFINED", "undef:$TEST_NOT_SET")
	root.Set("TEST_OVERRIDE_VARIABLE", "pkg1")
	root.Set("TEST_CROSSREF1", "$TEST_CROSSREF_VAL2")
	root.Set("TEST_CROSSREF_VAL1", "cross_pkg1")
	root.Set("START_COMMAND", "XYZ")

	c1 := root.NewChild()
	c1.Set("TEST_MERGE_VARIABLE", "pkg2:$TEST_MERGE_VARIABLE")
	c1.Set("TEST_OVERRIDE_VARIABLE", "pkg2")
	c1.Set("TEST_CROSSREF2", "$TEST_CROSSREF_VAL1")
	c1.Set("TEST_CROSSREF_VAL2", "cross_pkg2")
	c1.Set("START_COMMAND", "XYZ")

	envstrs := c1.Strings()

	// Sort the two list just in case.
	sort.Sort(sort.StringSlice(envstrs))
	sort.Sort(sort.StringSlice(expected))

	msg := make([]string, 0, len(envstrs))
	failed := false
	a := func(fmtstr string, args ...interface{}) {
		msg = append(msg, fmt.Sprintf(fmtstr, args...))
	}
	for i := 0; i < len(expected) || i < len(envstrs); i++ {
		if i >= len(expected) {
			a("\t'' > '%s'", envstrs[i])
		} else if i >= len(envstrs) {
			a("\t'%s' < ''", expected[i])
		} else if expected[i] != envstrs[i] {
			a("\t'%s' != '%s'", expected[i], envstrs[i])
		} else {
			a("\t'%s' == '%s'", expected[i], envstrs[i])
			continue
		}
		failed = true
	}
	if failed == true {
		tt.Fatalf(t, "results are not the same:\n%s", strings.Join(msg, "\n"))
	}
}
开发者ID:wallyqs,项目名称:util,代码行数:60,代码来源:envmap_test.go

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

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

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

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

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

示例11: TestReadAllOnClose

// Test that closing a domain socket will allow a call
// to ioutil.ReadAll to return properly.
func TestReadAllOnClose(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	sName := "/tmp/cntm_client_test.sock"
	l, err := net.Listen("unix", sName)
	if err != nil {
		t.Fatalf("Error listening to domain socket: %v", err)
	}
	defer os.Remove(sName)

	go func() {
		fd, err := l.Accept()
		if err != nil {
			t.Fatalf("Accept error: %v", err)
		}
		fd.Write([]byte("OK\n"))
		fd.Close()
	}()

	conn, err := net.Dial("unix", sName)
	if err != nil {
		t.Fatalf("Error connecting to domain socket: %v\n", err)
	}
	defer conn.Close()

	if err = conn.SetReadDeadline(time.Now().Add(time.Second)); err != nil {
		t.Fatalf("Got error setting a read deadline: %v", err)
	}

	_, err = ioutil.ReadAll(conn)
	if err != nil {
		t.Fatalf("Got an error on ioutil.ReadAll: %v\n", err)
	}
}
开发者ID:liyangdal,项目名称:kurma,代码行数:37,代码来源:client_test.go

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

示例13: TestCpuInfomation

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

	cpuMap := CpuInfo()
	tt.TestNotEqual(t, cpuMap["logicalCores"], "", "Number of logical cores in a system cannot be less than 1.")
	tt.TestNotEqual(t, cpuMap["physicalCores"], "", "Number of physical cores in a system cannot be less than 1.")
	tt.TestNotEqual(t, cpuMap["processorModel"], "", "Processor model must exist in the system.")
}
开发者ID:tstatler,项目名称:continuum-sample-apps,代码行数:9,代码来源:system_info_test.go

示例14: TestOtherSystemInfomation

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

	otherSystemInfoMap := OtherSystemInfo()
	tt.TestNotEqual(t, otherSystemInfoMap["hostname"], "", "Hostname of the system could not be retrieved.")
	tt.TestNotEqual(t, otherSystemInfoMap["ipv4_address"], "", "IPv4 address of the system could not be retrieved.")
	tt.TestNotEqual(t, otherSystemInfoMap["os_pagesize"], "", "OS page size of the system could not be retrieved.")
	tt.TestNotEqual(t, otherSystemInfoMap["target_architecture"], "", "Target architecture of the system could not be retrieved.")
	tt.TestNotEqual(t, otherSystemInfoMap["target_os"], "", "Target OS of the system could not be retrieved.")
}
开发者ID:tstatler,项目名称:continuum-sample-apps,代码行数:11,代码来源:system_info_test.go

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


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