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

Golang assert.NotNil函数代码示例

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

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



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

示例1: TestNodeCertificateRenewalsDoNotRequireToken

func TestNodeCertificateRenewalsDoNotRequireToken(t *testing.T) {
	tc := testutils.NewTestCA(t)
	defer tc.Stop()

	csr, _, err := ca.GenerateNewCSR()
	assert.NoError(t, err)

	role := api.NodeRoleManager
	issueRequest := &api.IssueNodeCertificateRequest{CSR: csr, Role: role}
	issueResponse, err := tc.NodeCAClients[2].IssueNodeCertificate(context.Background(), issueRequest)
	assert.NoError(t, err)
	assert.NotNil(t, issueResponse.NodeID)
	assert.Equal(t, api.NodeMembershipAccepted, issueResponse.NodeMembership)

	statusRequest := &api.NodeCertificateStatusRequest{NodeID: issueResponse.NodeID}
	statusResponse, err := tc.NodeCAClients[2].NodeCertificateStatus(context.Background(), statusRequest)
	assert.NoError(t, err)
	assert.Equal(t, api.IssuanceStateIssued, statusResponse.Status.State)
	assert.NotNil(t, statusResponse.Certificate.Certificate)
	assert.Equal(t, role, statusResponse.Certificate.Role)

	role = api.NodeRoleWorker
	issueRequest = &api.IssueNodeCertificateRequest{CSR: csr, Role: role}
	issueResponse, err = tc.NodeCAClients[1].IssueNodeCertificate(context.Background(), issueRequest)
	require.NoError(t, err)
	assert.NotNil(t, issueResponse.NodeID)
	assert.Equal(t, api.NodeMembershipAccepted, issueResponse.NodeMembership)

	statusRequest = &api.NodeCertificateStatusRequest{NodeID: issueResponse.NodeID}
	statusResponse, err = tc.NodeCAClients[2].NodeCertificateStatus(context.Background(), statusRequest)
	require.NoError(t, err)
	assert.Equal(t, api.IssuanceStateIssued, statusResponse.Status.State)
	assert.NotNil(t, statusResponse.Certificate.Certificate)
	assert.Equal(t, role, statusResponse.Certificate.Role)
}
开发者ID:yongtang,项目名称:swarmkit,代码行数:35,代码来源:server_test.go


示例2: TestLayerUpdate

func TestLayerUpdate(t *testing.T) {
	Open(&config.DatabaseConfig{Type: "memstore"})
	defer Close()

	l1 := &Layer{ID: "l1", OS: "os1", InstalledPackagesNodes: []string{"p1", "p2"}, RemovedPackagesNodes: []string{"p3", "p4"}, EngineVersion: 1}
	if assert.Nil(t, InsertLayer(l1)) {
		// Do not update layer content if the engine versions are equals
		l1b := &Layer{ID: "l1", OS: "os2", InstalledPackagesNodes: []string{"p1"}, RemovedPackagesNodes: []string{""}, EngineVersion: 1}
		if assert.Nil(t, InsertLayer(l1b)) {
			fl1b, err := FindOneLayerByID(l1.ID, FieldLayerAll)
			if assert.Nil(t, err) && assert.NotNil(t, fl1b) {
				assert.True(t, layerEqual(l1, fl1b), "layer contents are not equal, expected %v, have %s", l1, fl1b)
			}
		}

		// Update the layer content with new data and a higher engine version
		l1c := &Layer{ID: "l1", OS: "os2", InstalledPackagesNodes: []string{"p1", "p5"}, RemovedPackagesNodes: []string{"p6", "p7"}, EngineVersion: 2}
		if assert.Nil(t, InsertLayer(l1c)) {
			fl1c, err := FindOneLayerByID(l1c.ID, FieldLayerAll)
			if assert.Nil(t, err) && assert.NotNil(t, fl1c) {
				assert.True(t, layerEqual(l1c, fl1c), "layer contents are not equal, expected %v, have %s", l1c, fl1c)
			}
		}
	}
}
开发者ID:dwdm,项目名称:clair,代码行数:25,代码来源:layer_test.go


示例3: testAtomicPutCreate

func testAtomicPutCreate(t *testing.T, kv store.Store) {
	// Use a key in a new directory to ensure Stores will create directories
	// that don't yet exist.
	key := "testAtomicPutCreate/create"
	value := []byte("putcreate")

	// AtomicPut the key, previous = nil indicates create.
	success, _, err := kv.AtomicPut(key, value, nil, nil)
	assert.NoError(t, err)
	assert.True(t, success)

	// Get should return the value and an incremented index
	pair, err := kv.Get(key)
	assert.NoError(t, err)
	if assert.NotNil(t, pair) {
		assert.NotNil(t, pair.Value)
	}
	assert.Equal(t, pair.Value, value)

	// Attempting to create again should fail.
	success, _, err = kv.AtomicPut(key, value, nil, nil)
	assert.Error(t, err)
	assert.False(t, success)

	// This CAS should succeed, since it has the value from Get()
	success, _, err = kv.AtomicPut(key, []byte("PUTCREATE"), pair, nil)
	assert.NoError(t, err)
	assert.True(t, success)
}
开发者ID:winsx,项目名称:libnetwork,代码行数:29,代码来源:utils.go


示例4: TestMigrationStateStorageAndRetrieval

func (suite *IntegrationMigrateSuite) TestMigrationStateStorageAndRetrieval() {
	transform, err := NewConvert(testdata.ConvertDestination1, false, false, NewNullLogger())
	assert.Nil(suite.T(), err)

	err = transform.ConvertDirectory(testdata.ConvertSource1)
	assert.Nil(suite.T(), err)

	up := NewUp(testdata.ConvertDestination1, suite.Target)
	err = up.Migrate()
	assert.Nil(suite.T(), err)

	state, err := suite.Target.GetStatus()
	assert.Nil(suite.T(), err)
	assert.NotNil(suite.T(), state.Migrations)
	assert.Equal(suite.T(), up.Migrations.Len(), state.Migrations.Len())

	first, err := state.Migrations.First()
	assert.Nil(suite.T(), err)
	var leaf ConfigLeaf
	for _, entry := range first.Content.Entries {
		if entry.Path == "/default/alice" {
			leaf = entry
		}
	}
	assert.NotNil(suite.T(), leaf)
}
开发者ID:C2FO,项目名称:gull,代码行数:26,代码来源:migration_integration_test.go


示例5: TestOnDisconnect

func TestOnDisconnect(t *testing.T) {
	gnet.EraseMessages()
	d := newDefaultDaemon()
	c := gnetConnection(addr)
	var mirror uint32 = 100

	// Not blacklistable
	reason := gnet.DisconnectWriteFailed
	setupTestOnDisconnect(d, c, mirror)
	assert.NotPanics(t, func() { d.onGnetDisconnect(c, reason) })
	// Should not be in blacklist
	assert.Equal(t, len(d.Peers.Peers.Blacklist), 0)
	// Should no longer be in OutgoingConnections
	assert.Equal(t, len(d.OutgoingConnections), 0)
	// Should no longer be in d.ExpectingIntroductions
	assert.Equal(t, len(d.ExpectingIntroductions), 0)
	// Should be removed from the mirror, and the mirror dict for this ip
	// should be removed
	assert.Equal(t, len(d.mirrorConnections), 0)
	assert.Equal(t, len(d.ConnectionMirrors), 0)

	// Blacklistable
	reason = DisconnectIntroductionTimeout
	setupTestOnDisconnect(d, c, mirror)
	assert.NotPanics(t, func() { d.onGnetDisconnect(c, reason) })
	assert.Equal(t, len(d.Peers.Peers.Blacklist), 1)
	assert.NotNil(t, d.Peers.Peers.Blacklist[addr])
	// Should be in blacklist
	assert.Equal(t, len(d.Peers.Peers.Blacklist), 1)
	assert.NotNil(t, d.Peers.Peers.Blacklist[addr])
	// Should no longer be in OutgoingConnections
	assert.Equal(t, len(d.OutgoingConnections), 0)
	// Should no longer be in d.ExpectingIntroductions
	assert.Equal(t, len(d.ExpectingIntroductions), 0)
	// Should be removed from the mirror, and the mirror dict for this ip
	// should be removed
	assert.Equal(t, len(d.mirrorConnections), 0)
	assert.Equal(t, len(d.ConnectionMirrors), 0)
	// Cleanup
	delete(d.Peers.Peers.Blacklist, addr)

	// d.mirrorConnections should retain a submap if there are other ports
	// inside
	reason = gnet.DisconnectWriteFailed
	setupTestOnDisconnect(d, c, mirror)
	d.mirrorConnections[mirror][strings.Split(addrb, ":")[0]] = addrPort
	assert.NotPanics(t, func() { d.onGnetDisconnect(c, reason) })
	// Should not be in blacklist
	assert.Equal(t, len(d.Peers.Peers.Blacklist), 0)
	// Should no longer be in OutgoingConnections
	assert.Equal(t, len(d.OutgoingConnections), 0)
	// Should no longer be in d.ExpectingIntroductions
	assert.Equal(t, len(d.ExpectingIntroductions), 0)
	// Should be removed from the mirror, and the mirror dict for this ip
	// should be removed
	assert.Equal(t, len(d.mirrorConnections), 1)
	assert.Equal(t, len(d.mirrorConnections[mirror]), 1)
	assert.Equal(t, len(d.ConnectionMirrors), 0)
	shutdown(d)
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:60,代码来源:daemon_test.go


示例6: TestIsSameFile

func TestIsSameFile(t *testing.T) {
	absPath, err := filepath.Abs("../tests/files/")

	assert.NotNil(t, absPath)
	assert.Nil(t, err)

	fileInfo1, err := os.Stat(absPath + "/logs/test.log")
	fileInfo2, err := os.Stat(absPath + "/logs/system.log")

	assert.Nil(t, err)
	assert.NotNil(t, fileInfo1)
	assert.NotNil(t, fileInfo2)

	file1 := &File{
		FileInfo: fileInfo1,
	}

	file2 := &File{
		FileInfo: fileInfo2,
	}

	file3 := &File{
		FileInfo: fileInfo2,
	}

	assert.False(t, file1.IsSameFile(file2))
	assert.False(t, file2.IsSameFile(file1))

	assert.True(t, file1.IsSameFile(file1))
	assert.True(t, file2.IsSameFile(file2))

	assert.True(t, file3.IsSameFile(file2))
	assert.True(t, file2.IsSameFile(file3))
}
开发者ID:davidsoloman,项目名称:beats,代码行数:34,代码来源:file_test.go


示例7: TestGetAllUdp

func TestGetAllUdp(t *testing.T) {
	p := newProtocols()
	udp := p.GetAllUdp()
	assert.Nil(t, udp[1])
	assert.NotNil(t, udp[2])
	assert.NotNil(t, udp[3])
}
开发者ID:zyuyou,项目名称:beats,代码行数:7,代码来源:protos_test.go


示例8: TestGetAll

func TestGetAll(t *testing.T) {
	p := newProtocols()
	all := p.GetAll()
	assert.NotNil(t, all[1])
	assert.NotNil(t, all[2])
	assert.NotNil(t, all[3])
}
开发者ID:zyuyou,项目名称:beats,代码行数:7,代码来源:protos_test.go


示例9: TestRPCCreationOfDiffInstanceDiffCatalog

func TestRPCCreationOfDiffInstanceDiffCatalog(t *testing.T) {
	rep := createMockupReplication()
	close(rep.(*mockupReplication).syncChan) //Make sure no deadlock occur

	r := newInMemoryRegistry(nil, rep)

	catalog, err := r.GetCatalog(auth.NamespaceFrom("ns1"))
	assert.NoError(t, err)
	assert.NotNil(t, catalog)
	assert.NotEmpty(t, catalog)

	instance1 := newServiceInstance("Calc", "192.168.0.1", 9080)
	var err2 error
	instance1, err2 = catalog.Register(instance1)
	assert.NoError(t, err2)
	assert.NotNil(t, instance1)

	otherCatalog, err1 := r.GetCatalog(auth.NamespaceFrom("ns1"))
	assert.NoError(t, err1)
	assert.NotNil(t, otherCatalog)
	assert.NotEmpty(t, otherCatalog)
	assert.Equal(t, otherCatalog, catalog)

	instance2 := newServiceInstance("Calc", "192.168.0.2", 9082)
	var err3 error
	instance2, err3 = otherCatalog.Register(instance2)
	assert.NoError(t, err3)
	assert.NotNil(t, instance2)

	instances, err4 := catalog.List("Calc", protocolPredicate)
	assert.NoError(t, err4)
	assert.Len(t, instances, 2)
	assertContainsInstance(t, instances, instance1)
	assertContainsInstance(t, instances, instance2)
}
开发者ID:charshy,项目名称:registry,代码行数:35,代码来源:in_memory_registry_test.go


示例10: TestStoreDeleteDiretory

// Ensure that the store can delete a directory if recursive is specified.
func TestStoreDeleteDiretory(t *testing.T) {
	s := newStore()
	// create directory /foo
	s.Create("/foo", true, "", false, Permanent)
	// delete /foo with dir = true and recursive = false
	// this should succeed, since the directory is empty
	e, err := s.Delete("/foo", true, false)
	assert.Nil(t, err, "")
	assert.Equal(t, e.Action, "delete", "")
	// check pervNode
	assert.NotNil(t, e.PrevNode, "")
	assert.Equal(t, e.PrevNode.Key, "/foo", "")
	assert.Equal(t, e.PrevNode.Dir, true, "")

	// create directory /foo and directory /foo/bar
	s.Create("/foo/bar", true, "", false, Permanent)
	// delete /foo with dir = true and recursive = false
	// this should fail, since the directory is not empty
	_, err = s.Delete("/foo", true, false)
	assert.NotNil(t, err, "")

	// delete /foo with dir=false and recursive = true
	// this should succeed, since recursive implies dir=true
	// and recursively delete should be able to delete all
	// items under the given directory
	e, err = s.Delete("/foo", false, true)
	assert.Nil(t, err, "")
	assert.Equal(t, e.Action, "delete", "")

}
开发者ID:JeremyOT,项目名称:etcd,代码行数:31,代码来源:store_test.go


示例11: TestGetters

func TestGetters(t *testing.T) {
	assert.False(t, IsAuthenticatedFromContext(context.Background()))
	_, err := PoliciesFromContext(context.Background())
	assert.NotNil(t, err)
	_, err = SubjectFromContext(context.Background())
	assert.NotNil(t, err)
	_, err = TokenFromContext(context.Background())
	assert.NotNil(t, err)

	ctx := context.Background()
	claims := hjwt.ClaimsCarrier{"sub": "peter"}
	token := &jwt.Token{Valid: true}
	policies := []policy.Policy{}
	ctx = NewContextFromAuthValues(ctx, claims, token, policies)

	assert.True(t, IsAuthenticatedFromContext(ctx))
	policiesContext, err := PoliciesFromContext(ctx)
	assert.Nil(t, err)
	assert.Equal(t, policies, policiesContext)

	subjectContext, err := SubjectFromContext(ctx)
	assert.Nil(t, err)
	assert.Equal(t, claims.GetSubject(), subjectContext)

	tokenContext, err := TokenFromContext(ctx)
	assert.Nil(t, err)
	assert.Equal(t, token, tokenContext)
}
开发者ID:lmineiro,项目名称:hydra,代码行数:28,代码来源:auth_test.go


示例12: TestValidate

func TestValidate(t *testing.T) {
	f := FeatureFlag{
		Key:        "foo",
		Enabled:    false,
		Users:      []uint32{},
		Groups:     []string{},
		Percentage: 101,
	}

	err := f.Validate()
	assert.NotNil(t, err)
	assert.Equal(t, "Percentage must be between 0 and 100", err.Error())

	f.Percentage = 50
	f.Key = "ab"
	err = f.Validate()
	assert.NotNil(t, err)
	assert.Equal(t, "Feature key must be between 3 and 50 characters", err.Error())

	f.Key = "a&6"
	err = f.Validate()
	assert.NotNil(t, err)
	assert.Equal(t, "Feature key must only contain digits, lowercase letters and underscores", err.Error())

	f.Key = "foo"
	assert.Nil(t, f.Validate())
}
开发者ID:lacion,项目名称:feature-flags,代码行数:27,代码来源:feature_test.go


示例13: TestIssueNodeCertificateBrokenCA

func TestIssueNodeCertificateBrokenCA(t *testing.T) {
	if !testutils.External {
		t.Skip("test only applicable for external CA configuration")
	}

	tc := testutils.NewTestCA(t)
	defer tc.Stop()

	csr, _, err := ca.GenerateNewCSR()
	assert.NoError(t, err)

	tc.ExternalSigningServer.Flake()

	go func() {
		time.Sleep(250 * time.Millisecond)
		tc.ExternalSigningServer.Deflake()
	}()
	issueRequest := &api.IssueNodeCertificateRequest{CSR: csr, Token: tc.WorkerToken}
	issueResponse, err := tc.NodeCAClients[0].IssueNodeCertificate(context.Background(), issueRequest)
	assert.NoError(t, err)
	assert.NotNil(t, issueResponse.NodeID)
	assert.Equal(t, api.NodeMembershipAccepted, issueResponse.NodeMembership)

	statusRequest := &api.NodeCertificateStatusRequest{NodeID: issueResponse.NodeID}
	statusResponse, err := tc.NodeCAClients[0].NodeCertificateStatus(context.Background(), statusRequest)
	require.NoError(t, err)
	assert.Equal(t, api.IssuanceStateIssued, statusResponse.Status.State)
	assert.NotNil(t, statusResponse.Certificate.Certificate)
	assert.Equal(t, api.NodeRoleWorker, statusResponse.Certificate.Role)

}
开发者ID:yongtang,项目名称:swarmkit,代码行数:31,代码来源:server_test.go


示例14: assertOperation

func assertOperation(t *testing.T, op *spec.Operation, id, summary, description string, tags []string) {
	assert.NotNil(t, op)
	assert.Equal(t, summary, op.Summary)
	assert.Equal(t, description, op.Description)
	assert.Equal(t, id, op.ID)
	assert.EqualValues(t, tags, op.Tags)
	assert.EqualValues(t, []string{"application/json", "application/x-protobuf"}, op.Consumes)
	assert.EqualValues(t, []string{"application/json", "application/x-protobuf"}, op.Produces)
	assert.EqualValues(t, []string{"http", "https", "ws", "wss"}, op.Schemes)
	assert.Len(t, op.Security, 2)
	_, ok := op.Security[0]["api_key"]
	assert.True(t, ok)

	vv, ok := op.Security[1]["oauth"]
	assert.True(t, ok)
	assert.EqualValues(t, []string{"read", "write"}, vv)

	assert.NotNil(t, op.Responses.Default)
	assert.Equal(t, "#/responses/genericError", op.Responses.Default.Ref.String())

	rsp, ok := op.Responses.StatusCodeResponses[200]
	assert.True(t, ok)
	assert.Equal(t, "#/responses/someResponse", rsp.Ref.String())
	rsp, ok = op.Responses.StatusCodeResponses[422]
	assert.True(t, ok)
	assert.Equal(t, "#/responses/validationError", rsp.Ref.String())
}
开发者ID:jak-atx,项目名称:vic,代码行数:27,代码来源:routes_test.go


示例15: TestMetadataCreateAllDropAllError

func TestMetadataCreateAllDropAllError(t *testing.T) {
	accounts := Table(
		"account",
		Column("id", Type("UUID")),
		PrimaryKey("id"),
	)
	engine, err := New("postgres", postgresDsn)
	metadata := MetaData()

	engine.Dialect().SetEscaping(true)
	assert.Nil(t, err)
	metadata.AddTable(accounts)
	err = metadata.CreateAll(engine)
	assert.Nil(t, err)

	engineNew, err := New("postgres", postgresDsn)
	engineNew.Dialect().SetEscaping(true)
	metadataNew := MetaData()
	assert.Nil(t, err)
	metadataNew.AddTable(accounts)
	err = metadataNew.CreateAll(engineNew)
	assert.NotNil(t, err)

	err = metadataNew.DropAll(engine)
	assert.Nil(t, err)

	err = metadataNew.DropAll(engineNew)
	assert.NotNil(t, err)
}
开发者ID:aacanakin,项目名称:qb,代码行数:29,代码来源:metadata_test.go


示例16: TestMergeFlagValueNewList

func TestMergeFlagValueNewList(t *testing.T) {
	config, _ := ucfg.NewFrom(map[string]interface{}{
		"c.0.b":  true,
		"c.0.b2": true,
		"c.0.i":  42,
		"c.0.c":  3.14,
		"c.0.s":  "wrong",
	}, ucfg.PathSep("."))

	cliConfig, err := parseTestFlags("-D c.0.s=string -D c.0.f=3.14 -D c.1.b=true")
	assert.NoError(t, err)

	err = config.Merge(cliConfig, ucfg.PathSep("."))
	assert.NoError(t, err)

	// validate
	sub, err := config.Child("c", 0)
	assert.NoError(t, err)
	assert.NotNil(t, sub)
	if sub != nil {
		checkFields(t, sub)
	}

	sub, err = config.Child("c", 1)
	assert.NoError(t, err)
	assert.NotNil(t, sub)
	if sub == nil {
		return
	}

	b, err := sub.Bool("b", -1)
	assert.NoError(t, err)
	assert.True(t, b)
}
开发者ID:elastic,项目名称:go-ucfg,代码行数:34,代码来源:value_test.go


示例17: TestWrite

func TestWrite(t *testing.T) {
	const s string = "All work and no play makes Jack a dull boy"
	dir, err := ioutil.TempDir("", "testrotlog")
	if err != nil {
		fmt.Println("Failed to create test dir in TestIfFileExists, skipping...")
		return
	}
	r, err := InitRotlog(dir+"/test", 43, 3)
	assert.Nil(t, err)
	assert.NotNil(t, r)
	assert.Equal(t, dir+"/test", r.filename)
	assert.Equal(t, true, r.fileNumberExists(0))
	assert.NotNil(t, r.current)

	for i := 0; i < 10; i++ {
		n, err := r.Write([]byte(s))
		if err != nil {
			t.Errorf(err.Error())
		}
		assert.Equal(t, len(s)+1, n)
		//on lit le fichier, pour voir
		content, err := ioutil.ReadFile(r.filename)
		if err != nil {
			t.Errorf(err.Error())
		}
		assert.Equal(t, s+"\n", string(content))
		if i < 3 {
			assert.Equal(t, true, r.fileNumberExists(i))
		} else {
			assert.Equal(t, false, r.fileNumberExists(i))
		}
	}
	os.RemoveAll(dir)
}
开发者ID:amundi,项目名称:eschecker,代码行数:34,代码来源:rotlog_test.go


示例18: TestNewHydre

func TestNewHydre(t *testing.T) {
	h, err := NewHydre("test/good-conf.yml")
	assert.Nil(t, err)
	assert.Equal(t, 10, h.Timeout)
	assert.Len(t, h.Daemons, 2)
	assert.Contains(t, h.Daemons, &Daemon{
		Name:        "daemon1",
		Command:     []string{"start", "daemon1"},
		StopCommand: []string{"stop", "daemon1"},
		PidFile:     "path/to/pidfile",
		LogFiles:    []string{"1.log", "2.log"},
	})
	assert.Contains(t, h.Daemons, &Daemon{
		Name:    "daemon2",
		Command: []string{"start", "daemon2"},
	})

	h, err = NewHydre("test/bad-conf.yml")
	assert.NotNil(t, err)
	assert.Nil(t, h)

	h, err = NewHydre("does-not-exist.yml")
	assert.NotNil(t, err)
	assert.Nil(t, h)
}
开发者ID:sarulabs,项目名称:hydre,代码行数:25,代码来源:hydre_test.go


示例19: TestGetAllTcp

func TestGetAllTcp(t *testing.T) {
	p := newProtocols()
	tcp := p.GetAllTcp()
	assert.NotNil(t, tcp[1])
	assert.Nil(t, tcp[2])
	assert.NotNil(t, tcp[3])
}
开发者ID:zyuyou,项目名称:beats,代码行数:7,代码来源:protos_test.go


示例20: TestFindClientByClientID

func (suite *OauthTestSuite) TestFindClientByClientID() {
	var (
		client *Client
		err    error
	)

	// When we try to find a client with a bogus client ID
	client, err = suite.service.FindClientByClientID("bogus")

	// Client object should be nil
	assert.Nil(suite.T(), client)

	// Correct error should be returned
	if assert.NotNil(suite.T(), err) {
		assert.Equal(suite.T(), ErrClientNotFound, err)
	}

	// When we try to find a client with a valid cliend ID
	client, err = suite.service.FindClientByClientID("test_client_1")

	// Error should be nil
	assert.Nil(suite.T(), err)

	// Correct client object should be returned
	if assert.NotNil(suite.T(), client) {
		assert.Equal(suite.T(), "test_client_1", client.Key)
	}
}
开发者ID:chenhougen,项目名称:go-oauth2-server,代码行数:28,代码来源:client_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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