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

Golang assert.NoErr函数代码示例

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

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



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

示例1: getMockCluster

func getMockCluster(t *testing.T) models.Cluster {
	mockData, err := mocks.GetMockCluster()
	assert.NoErr(t, err)
	mockCluster, err := ParseJSONCluster(mockData)
	assert.NoErr(t, err)
	return mockCluster
}
开发者ID:deis,项目名称:workflow-manager,代码行数:7,代码来源:data_test.go


示例2: TestTarFiles

func TestTarFiles(t *testing.T) {
	dir, err := tests.DataDir()
	assert.NoErr(t, err)
	rdr, err := tarFiles(dir, tests.ExpectedDataSlice())
	assert.NoErr(t, err)
	tr := tar.NewReader(rdr)
	set := tests.ExpectedDataSet()
	numFound := 0
	for {
		hdr, err := tr.Next()
		if err == io.EOF {
			break
		} else if err != nil {
			t.Errorf("reading next record in archive (%s)", err)
			continue
		}
		_, found := set[hdr.Name]
		if !found {
			t.Errorf("unknown file %s", hdr.Name)
			continue
		}
		numFound++
	}
	if numFound != len(set) {
		t.Fatalf("found only %d of %d files in the testdata dir", len(tests.ExpectedDataSlice()), numFound)
	}

}
开发者ID:arschles,项目名称:goprox,代码行数:28,代码来源:upload_test.go


示例3: TestNewestSemVer

func TestNewestSemVer(t *testing.T) {
	// Verify that NewestSemVer returns correct semver string for larger major, minor, and patch substrings
	const v1Lower = "2.0.0"
	v2s := [3]string{"3.0.0", "2.1.0", "2.0.1"}
	for _, v2 := range v2s {
		newest, err := NewestSemVer(v1Lower, v2)
		assert.NoErr(t, err)
		if newest != v2 {
			fmt.Printf("expected %s to be greater than %s\n", v2, v1Lower)
			t.Fatal("semver comparison failure")
		}
	}
	// Verify that NewestSemVer returns correct semver string for smaller major, minor, and patch substrings
	const v1Higher = "2.4.5"
	v2s = [3]string{"1.99.23", "2.3.99", "2.4.4"}
	for _, v2 := range v2s {
		newest, err := NewestSemVer(v1Higher, v2)
		assert.NoErr(t, err)
		if newest != v1Higher {
			fmt.Printf("expected %s to be greater than %s\n", v1Higher, v2)
			t.Fatal("semver comparison failure")
		}
	}
	// Verify that NewestSemVer returns correct semver string for comparing equal strings
	const v1Equal = "1.0.0"
	v2 := v1Equal
	newest, err := NewestSemVer(v1Equal, v2)
	assert.NoErr(t, err)
	if newest != v1Equal && newest != v2 {
		fmt.Printf("expected %s to be equal to %s and %s\n", newest, v1Equal, v2)
		t.Fatal("semver comparison failure")
	}
}
开发者ID:deis,项目名称:workflow-manager,代码行数:33,代码来源:data_test.go


示例4: TestPushInvalidArgsLength

// TestPushInvalidArgsLength tests trying to do a push with only the command, not the repo
func TestPushInvalidArgsLength(t *testing.T) {
	const testingServerAddr = "127.0.0.1:2252"
	key, err := sshTestingHostKey()
	assert.NoErr(t, err)

	cfg, err := serverConfigure()
	assert.NoErr(t, err)
	cfg.AddHostKey(key)

	c := NewCircuit()
	pushLock := NewInMemoryRepositoryLock(0)
	runServer(cfg, c, pushLock, testingServerAddr, 0*time.Second, t)

	// Give server time to initialize.
	time.Sleep(200 * time.Millisecond)

	assert.Equal(t, c.State(), ClosedState, "circuit state")

	// Connect to the server and issue env var set. This should return true.
	client, err := ssh.Dial("tcp", testingServerAddr, clientConfig())
	assert.NoErr(t, err)

	// check for invalid length of arguments
	sess, err := client.NewSession()
	assert.NoErr(t, err)
	defer sess.Close()
	if out, err := sess.Output("git-upload-pack"); err == nil {
		t.Errorf("Expected an error but '%s' was received", out)
	} else if string(out) != "" {
		t.Errorf("Expected , got '%s'", out)
	}
}
开发者ID:bacongobbler,项目名称:builder,代码行数:33,代码来源:server_test.go


示例5: TestRefreshAvailableVersions

func TestRefreshAvailableVersions(t *testing.T) {
	desc := "this is test1"
	updAvail := "nothing"
	expectedCompVsns := operations.GetComponentsByLatestReleaseOKBodyBody{
		Data: []*models.ComponentVersion{
			&models.ComponentVersion{
				Component:       &models.Component{Name: "test1", Description: &desc},
				Version:         &models.Version{Train: "testTrain"},
				UpdateAvailable: &updAvail,
			},
		},
	}
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json; charset=UTF-8")
		if err := json.NewEncoder(w).Encode(expectedCompVsns); err != nil {
			http.Error(w, "error encoding JSON", http.StatusInternalServerError)
			return
		}
	}))
	defer ts.Close()
	apiclient, err := config.GetSwaggerClient(ts.URL)
	assert.NoErr(t, err)
	vsns := availableVersionsFromAPI{
		rwm:             new(sync.RWMutex),
		baseVersionsURL: ts.URL,
		apiClient:       apiclient,
	}
	retCompVsns, err := vsns.Refresh(models.Cluster{})
	assert.NoErr(t, err)
	assert.Equal(t, len(retCompVsns), len(expectedCompVsns.Data), "number of component versions")
}
开发者ID:deis,项目名称:workflow-manager,代码行数:31,代码来源:available_versions_test.go


示例6: TestIDHandler

func TestIDHandler(t *testing.T) {
	idHandler := IDHandler(&mockClusterID{})
	resp, err := getTestHandlerResponse(idHandler)
	assert.NoErr(t, err)
	assert200(t, resp)
	respData, err := ioutil.ReadAll(resp.Body)
	assert.NoErr(t, err)
	assert.Equal(t, string(respData), mockID, "ID value")
}
开发者ID:deis,项目名称:workflow-manager,代码行数:9,代码来源:handlers_test.go


示例7: TestGetID

// Calls GetID twice, the first time we expect our passed-in struct w/ Get() method
// to be invoked, the 2nd time we expect to receive the same value back (cached in memory)
// and for the passed-in Get() method to be ignored
func TestGetID(t *testing.T) {
	cid := &testClusterID{}
	id, err := GetID(cid)
	assert.NoErr(t, err)
	assert.Equal(t, id, mockClusterID, "cluster ID value")
	cid.cache = "something else"
	id, err = GetID(cid)
	assert.NoErr(t, err)
	assert.Equal(t, id, "something else", "cluster ID value")
}
开发者ID:deis,项目名称:workflow-manager,代码行数:13,代码来源:data_test.go


示例8: TestCreatePreReceiveHook

func TestCreatePreReceiveHook(t *testing.T) {
	const gitHome = "TestGitHome"
	gopath := os.Getenv("GOPATH")
	repoPath := filepath.Join(gopath, "src", "github.com", "deis", "builder", "testdata")
	assert.NoErr(t, createPreReceiveHook(gitHome, repoPath))
	hookBytes, err := ioutil.ReadFile(filepath.Join(repoPath, "hooks", "pre-receive"))
	assert.NoErr(t, err)
	hookStr := string(hookBytes)
	gitHomeIdx := strings.Index(hookStr, fmt.Sprintf("GIT_HOME=%s", gitHome))
	assert.False(t, gitHomeIdx == -1, "GIT_HOME was not found")
}
开发者ID:bacongobbler,项目名称:builder,代码行数:11,代码来源:git_test.go


示例9: TestGetAvailableVersions

// Calls GetAvailableVersions twice, the first time we expect our passed-in struct w/ Refresh() method
// to be invoked, the 2nd time we expect to receive the same value back (cached in memory)
// and for the passed-in Refresh() method to be ignored
func TestGetAvailableVersions(t *testing.T) {
	mock := getMockComponentVersions()
	var mockVersions []models.ComponentVersion
	assert.NoErr(t, json.Unmarshal(mock, &mockVersions))
	versions, err := GetAvailableVersions(testAvailableVersions{}, models.Cluster{})
	assert.NoErr(t, err)
	assert.Equal(t, versions, mockVersions, "component versions data")
	versions, err = GetAvailableVersions(shouldBypassAvailableVersions{}, models.Cluster{})
	assert.NoErr(t, err)
	assert.Equal(t, versions, mockVersions, "component versions data")
}
开发者ID:deis,项目名称:workflow-manager,代码行数:14,代码来源:available_versions_test.go


示例10: TestWritePlainText

func TestWritePlainText(t *testing.T) {
	const text = "foo"
	handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		writePlainText(text, w)
	})
	resp, err := getTestHandlerResponse(handler)
	assert.NoErr(t, err)
	assert.Equal(t, resp.Header.Get("Content-Type"), "text/plain", "Content-Type value")
	respData, err := ioutil.ReadAll(resp.Body)
	assert.NoErr(t, err)
	assert.Equal(t, string(respData), text, "text response")
}
开发者ID:deis,项目名称:workflow-manager,代码行数:12,代码来源:handlers_test.go


示例11: TestReceive

// TestServer tests the SSH server.
//
// This listens on the non-standard port 2244 of localhost. This will generate
// an entry in your known_hosts file, and will tie that to the testing key
// used here. It's not recommended that you try to start another SSH server on
// the same port (at a later time) or else you will have key issues that you
// must manually resolve.
func TestReceive(t *testing.T) {
	const testingServerAddr = "127.0.0.1:2244"
	key, err := sshTestingHostKey()
	assert.NoErr(t, err)

	cfg, err := serverConfigure()
	assert.NoErr(t, err)
	cfg.AddHostKey(key)

	c := NewCircuit()
	pushLock := NewInMemoryRepositoryLock(0)
	runServer(cfg, c, pushLock, testingServerAddr, time.Duration(0), t)

	// Give server time to initialize.
	time.Sleep(200 * time.Millisecond)
	assert.Equal(t, c.State(), ClosedState, "circuit state")

	// Connect to the server and issue env var set. This should return true.
	client, err := ssh.Dial("tcp", testingServerAddr, clientConfig())
	if err != nil {
		t.Fatalf("Failed to connect client to local server: %s", err)
	}
	sess, err := client.NewSession()
	if err != nil {
		t.Fatalf("Failed to create client session: %s", err)
	}
	defer sess.Close()

	if err := sess.Setenv("HELLO", "world"); err != nil {
		t.Fatal(err)
	}

	if out, err := sess.Output("ping"); err != nil {
		t.Errorf("Output '%s' Error %s", out, err)
	} else if string(out) != "pong" {
		t.Errorf("Expected 'pong', got '%s'", out)
	}

	// Create a new session because the success of the last one closed the
	// connection.
	sess, err = client.NewSession()
	if err != nil {
		t.Fatalf("Failed to create client session: %s", err)
	}
	if err := sess.Run("illegal"); err == nil {
		t.Fatalf("expected a failed run with command 'illegal'")
	}
	if err := sess.Run("illegal command"); err == nil {
		t.Fatalf("expected a failed run with command 'illegal command'")
	}

}
开发者ID:bacongobbler,项目名称:builder,代码行数:59,代码来源:server_test.go


示例12: TestGetID

func TestGetID(t *testing.T) {
	const idRoute = "/id"
	resp, apiServer, err := testGet(idRoute)
	if apiServer != nil {
		apiServer.Close()
	}
	assert.NoErr(t, err)
	assert200(t, resp)
	respData, err := ioutil.ReadAll(resp.Body)
	assert.NoErr(t, err)
	mockData, err := mocks.GetMockClusterID()
	assert.NoErr(t, err)
	assert.Equal(t, string(respData), mockData, "id data response")
}
开发者ID:deis,项目名称:workflow-manager,代码行数:14,代码来源:boot_test.go


示例13: TestHTTPQueueOperations

func TestHTTPQueueOperations(t *testing.T) {
	srv := testsrv.StartServer(makeQHandler())
	defer srv.Close()
	urlStrSplit := strings.Split(strings.TrimPrefix(srv.URLStr(), "http://"), ":")
	assert.Equal(t, 2, len(urlStrSplit), "number of elements in the URL string")
	host := urlStrSplit[0]
	port, err := strconv.Atoi(urlStrSplit[1])
	assert.NoErr(t, err)
	if port > 65535 {
		t.Fatalf("port [%d] not a uint16", port)
	}
	cl := NewHTTPClient(SchemeHTTP, host, uint16(port))
	assert.NoErr(t, qOperations(cl))
}
开发者ID:romand,项目名称:gorion,代码行数:14,代码来源:http_client_test.go


示例14: TestConcurrentPushSameRepo

// TestConcurrentPushSameRepo tests many concurrent pushes, each to the same repo
func TestConcurrentPushSameRepo(t *testing.T) {
	const testingServerAddr = "127.0.0.1:2245"
	key, err := sshTestingHostKey()
	assert.NoErr(t, err)

	cfg, err := serverConfigure()
	assert.NoErr(t, err)
	cfg.AddHostKey(key)

	c := NewCircuit()
	pushLock := NewInMemoryRepositoryLock(500 * time.Millisecond)
	runServer(cfg, c, pushLock, testingServerAddr, 2*time.Second, t)

	// Give server time to initialize.
	time.Sleep(200 * time.Millisecond)

	assert.Equal(t, c.State(), ClosedState, "circuit state")

	// Connect to the server and issue env var set. This should return true.
	client, err := ssh.Dial("tcp", testingServerAddr, clientConfig())
	assert.NoErr(t, err)

	const numPushers = 4
	outCh := make(chan *sshSessionOutput, numPushers)
	for i := 0; i < numPushers; i++ {
		go func() {
			sess, newSessErr := client.NewSession()
			assert.NoErr(t, newSessErr)
			defer sess.Close()
			out, outErr := sess.Output("git-upload-pack /demo.git")
			outCh <- &sshSessionOutput{outStr: string(out), err: outErr}
		}()
	}

	// ensure at least 1 output was successful
	foundOK := false
	to := 1 * time.Second
	for i := 0; i < numPushers; i++ {
		select {
		case sessOut := <-outCh:
			if sessOut.outStr == "OK" {
				foundOK = true
			}
		case <-time.After(to):
			t.Fatalf("didn't receive an output within %s", to)
		}
	}
	assert.True(t, foundOK, "no SSH requests were successful")
}
开发者ID:bacongobbler,项目名称:builder,代码行数:50,代码来源:server_test.go


示例15: TestHTTPDo

func TestHTTPDo(t *testing.T) {
	hndl := func(http.ResponseWriter, *http.Request) {}
	srv := testsrv.StartServer(http.HandlerFunc(hndl))
	defer srv.Close()
	transport := &http.Transport{}
	client := &http.Client{Transport: transport}
	req, err := http.NewRequest("GET", srv.URLStr(), strings.NewReader(""))
	assert.NoErr(t, err)
	err = HTTPDo(context.Background(), client, transport, req, func(*http.Response, error) error {
		return nil
	})
	assert.NoErr(t, err)
	recv := srv.AcceptN(1, 100*time.Millisecond)
	assert.Equal(t, 1, len(recv), "number of received requests")
}
开发者ID:romand,项目名称:gorion,代码行数:15,代码来源:http_util_test.go


示例16: TestClientAcquireLock

func TestClientAcquireLock(t *testing.T) {
	mut := new(sync.Mutex)
	lockID := NewLockID()
	router := mux.NewRouter()
	registerLockHandler(router, mut, lockID)
	registerUnlockHandler(router, mut, lockID)
	srv := httptest.NewServer(router)
	defer srv.Close()

	baseURL := srv.URL
	lid, err := AcquireLock(http.DefaultClient, baseURL)
	assert.NoErr(t, err)
	assert.Equal(t, lockID.id, lid, "resulting lock IDs")
	assert.NoErr(t, ReleaseLock(http.DefaultClient, baseURL, lid))
}
开发者ID:bacongobbler,项目名称:riak,代码行数:15,代码来源:client_test.go


示例17: TestGetFiles

func TestGetFiles(t *testing.T) {
	dir, err := tests.DataDir()
	assert.NoErr(t, err)
	files, err := getFiles(dir)
	assert.NoErr(t, err)
	expected := tests.ExpectedDataSlice()
	set := map[string]struct{}{}
	for _, file := range files {
		set[file] = struct{}{}
	}
	for _, ex := range expected {
		_, ok := set[ex]
		assert.True(t, ok, "file %s was not found", ex)
	}
}
开发者ID:arschles,项目名称:goprox,代码行数:15,代码来源:upload_test.go


示例18: TestParse

func TestParse(t *testing.T) {
	//TODO: use gogenerate to generate valid html templates
	//http://godoc.org/github.com/arschles/gogenerate

	tmpl := `
    <html>
      <head>
        <title>hello {{.name}}</title>
      </head>
      <body>
        {{.greeting}}
      </body>
    </html>
  `
	fileName := "mytmpl.tmpl"
	tmplBytes := []byte(tmpl)
	expectedErr := errors.New("template not found")
	assetFunc := createValidAssetFunc(fileName, tmplBytes, expectedErr)

	tmpl1, err1 := New("test", assetFunc).Parse(fileName)
	assert.NoErr(t, err1)
	assert.False(t, tmpl1 == nil, "tmpl1 was nil when it should not have been")
	tmpl2, err2 := New("test1", assetFunc).Parse(fileName + fileName)
	assert.Err(t, err2, expectedErr)
	assert.True(t, tmpl2 == nil, "tmpl2 was not nil when it should have been")

	//TODO: check actual template output
	name := "Aaron"
	tmplData := map[string]string{
		"name": name,
	}
	buf1 := bytes.NewBuffer([]byte{})
	executeErr1 := tmpl1.Execute(buf1, tmplData)
	stdTmpl, stdTmplParseErr := template.New("referenceTest").Parse(tmpl)
	assert.NoErr(t, stdTmplParseErr)
	buf2 := bytes.NewBuffer([]byte{})
	executeErr2 := stdTmpl.Execute(buf2, tmplData)

	assert.NoErr(t, executeErr1)
	assert.NoErr(t, executeErr2)

	bytes1 := buf1.Bytes()
	bytes2 := buf2.Bytes()

	assert.True(t,
		string(bytes1) == string(bytes2),
		"actual template output %s is not equal expected %s", string(bytes1), string(bytes2))
}
开发者ID:topscore,项目名称:sup,代码行数:48,代码来源:template_test.go


示例19: TestCreateTplCtx

func TestCreateTplCtx(t *testing.T) {
	tplDir := "rootfs/templates"
	ctx := createTplCtx(tplDir, funcs)
	tpl, err := ctx.Prepare(tpl.NewFiles("index.html"))
	assert.NoErr(t, err)
	assert.NotNil(t, tpl, "returned template")
}
开发者ID:arschles,项目名称:goprox,代码行数:7,代码来源:main_test.go


示例20: TestGetDetailsFromDockerConfigSecretSuccess

func TestGetDetailsFromDockerConfigSecretSuccess(t *testing.T) {
	encToken := base64.StdEncoding.EncodeToString([]byte("testuser:testpassword"))
	auth := []byte(`
    {
    "auths": {
              "https://test.io": {
                  "auth": "` + encToken + `",
                  "email": "[email protected]"
              }
          }
    }
`)
	expectedData := map[string]string{"DEIS_REGISTRY_USERNAME": "testuser", "DEIS_REGISTRY_PASSWORD": "testpassword", "DEIS_REGISTRY_HOSTNAME": "https://test.io"}
	data := make(map[string][]byte)
	data[api.DockerConfigJsonKey] = auth
	secret := api.Secret{Data: data}
	getter := &k8s.FakeSecret{
		FnGet: func(string) (*api.Secret, error) {
			return &secret, nil
		},
	}
	regData, err := getDetailsFromDockerConfigSecret(getter, testSecret)
	assert.NoErr(t, err)
	assert.Equal(t, expectedData, regData, "registry details")

}
开发者ID:mboersma,项目名称:builder,代码行数:26,代码来源:registry_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang assert.True函数代码示例发布时间:2022-05-24
下一篇:
Golang assert.Equal函数代码示例发布时间: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