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

Golang require.NotNil函数代码示例

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

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



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

示例1: TestLoadLotsOfHardware

func TestLoadLotsOfHardware(t *testing.T) {
	context := make(map[string]interface{})

	context[constants.CTX_HARDWARE_FOLDERS] = []string{"downloaded_board_manager_stuff", "downloaded_hardware", filepath.Join("..", "hardware"), "hardware", "user_hardware"}

	loader := builder.HardwareLoader{}
	err := loader.Run(context)
	NoError(t, err)

	packages := context[constants.CTX_HARDWARE].(map[string]*types.Package)

	if runtime.GOOS == "windows" {
		//a package is a symlink, and windows does not support them
		require.Equal(t, 4, len(packages))
	} else {
		require.Equal(t, 5, len(packages))
	}

	require.NotNil(t, packages["arduino"])
	require.NotNil(t, packages["my_avr_platform"])

	require.Equal(t, 3, len(packages["arduino"].Platforms))
	require.Equal(t, 20, len(packages["arduino"].Platforms["avr"].Boards))
	require.Equal(t, 2, len(packages["arduino"].Platforms["sam"].Boards))
	require.Equal(t, 2, len(packages["arduino"].Platforms["samd"].Boards))

	require.Equal(t, 1, len(packages["my_avr_platform"].Platforms))
	require.Equal(t, 2, len(packages["my_avr_platform"].Platforms["avr"].Boards))

	if runtime.GOOS != "windows" {
		require.Equal(t, 1, len(packages["my_symlinked_avr_platform"].Platforms))
		require.Equal(t, 2, len(packages["my_symlinked_avr_platform"].Platforms["avr"].Boards))
	}
}
开发者ID:ricklon,项目名称:arduino-builder,代码行数:34,代码来源:hardware_loader_test.go


示例2: TestTracingPropagates

func TestTracingPropagates(t *testing.T) {
	WithVerifiedServer(t, nil, func(ch *Channel, hostPort string) {
		handler := &traceHandler{t: t, ch: ch}
		json.Register(ch, json.Handlers{
			"call": handler.call,
		}, handler.onError)

		ctx, cancel := json.NewContext(time.Second)
		defer cancel()

		peer := ch.Peers().GetOrAdd(ch.PeerInfo().HostPort)
		var response TracingResponse
		require.NoError(t, json.CallPeer(ctx, peer, ch.PeerInfo().ServiceName, "call", &TracingRequest{
			ForwardCount: 1,
		}, &response))

		clientSpan := CurrentSpan(ctx)
		require.NotNil(t, clientSpan)
		assert.Equal(t, uint64(0), clientSpan.ParentID())

		assert.Equal(t, uint64(0), clientSpan.ParentID())
		assert.NotEqual(t, uint64(0), clientSpan.TraceID())
		assert.Equal(t, clientSpan.TraceID(), response.TraceID)
		assert.Equal(t, clientSpan.SpanID(), response.ParentID)
		assert.Equal(t, response.TraceID, response.SpanID, "traceID = spanID for root span")

		nestedResponse := response.Child
		require.NotNil(t, nestedResponse)
		assert.Equal(t, clientSpan.TraceID(), nestedResponse.TraceID)
		assert.Equal(t, response.SpanID, nestedResponse.ParentID)
		assert.NotEqual(t, response.SpanID, nestedResponse.SpanID)
	})
}
开发者ID:hustxiaoc,项目名称:tchannel,代码行数:33,代码来源:tracing_test.go


示例3: verifyCacheFactoryCluster

// verifyCacheFactoryCluster performs assertions over a ClusterInfo structure,
// based on the values and structure generated by cacheFactory.
func verifyCacheFactoryCluster(clinfo *ClusterInfo, t *testing.T) {
	assert := assert.New(t)
	assert.NotNil(clinfo.Nodes["hostname2"])
	node2 := clinfo.Nodes["hostname2"]
	assert.NotEmpty(node2.Metrics)
	assert.Len(node2.FreeContainers, 1)
	assert.NotNil(node2.FreeContainers["free_container1"])

	assert.NotNil(clinfo.Nodes["hostname3"])
	node3 := clinfo.Nodes["hostname3"]
	assert.NotEmpty(node3.Metrics)

	assert.NotNil(clinfo.Namespaces["test"])
	namespace := clinfo.Namespaces["test"]

	assert.NotNil(namespace.Pods)
	pod1_ptr := namespace.Pods["pod1"]
	require.NotNil(t, pod1_ptr)
	assert.Equal(pod1_ptr, node2.Pods["pod1"])
	assert.Len(pod1_ptr.Containers, 2)
	pod2_ptr := namespace.Pods["pod2"]
	require.NotNil(t, pod2_ptr)
	assert.Equal(pod2_ptr, node3.Pods["pod2"])
	assert.Len(pod2_ptr.Containers, 2)
}
开发者ID:kshelton,项目名称:heapster,代码行数:27,代码来源:impl_test.go


示例4: TestListWorkItemType

// TestListWorkItemType tests if we can find the work item types
// "person" and "animal" in the list of work item types
func (s *workItemTypeSuite) TestListWorkItemType() {
	defer cleaner.DeleteCreatedEntities(s.DB)()

	// Create the work item type first and try to read it back in
	_, witAnimal := s.createWorkItemTypeAnimal()
	require.NotNil(s.T(), witAnimal)
	_, witPerson := s.createWorkItemTypePerson()
	require.NotNil(s.T(), witPerson)

	// Fetch a single work item type
	// Paging in the format <start>,<limit>"
	page := "0,-1"
	_, witCollection := test.ListWorkitemtypeOK(s.T(), nil, nil, s.typeCtrl, &page)

	require.NotNil(s.T(), witCollection)
	require.Nil(s.T(), witCollection.Validate())

	// Check the number of found work item types
	require.Condition(s.T(), func() bool {
		return (len(witCollection) >= 2)
	}, "At least two work item types must exist (animal and person), but only %d exist.", len(witCollection))

	// Search for the work item types that must exist at minimum
	toBeFound := 2
	for i := 0; i < len(witCollection) && toBeFound > 0; i++ {
		if witCollection[i].Name == "person" || witCollection[i].Name == "animal" {
			s.T().Log("Found work item type in collection: ", witCollection[i].Name)
			toBeFound--
		}
	}
	require.Exactly(s.T(), 0, toBeFound, "Not all required work item types (animal and person) where found.")
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:34,代码来源:workitemtype_blackbox_test.go


示例5: TestParseMutationAndQuery

func TestParseMutationAndQuery(t *testing.T) {
	query := `
		mutation {
			set {
				<name> <is> <something> .
				<hometown> <is> <san francisco> .
			}
			delete {
				<name> <is> <something-else> .
			}
		}
		query {
			me(_xid_: tomhanks) {
				name
				hometown
			}
		}
	`
	gq, mu, err := Parse(query)
	require.NoError(t, err)
	require.NotNil(t, mu)
	require.NotEqual(t, strings.Index(mu.Set, "<name> <is> <something> ."), -1)
	require.NotEqual(t, strings.Index(mu.Set, "<hometown> <is> <san francisco> ."), -1)
	require.NotEqual(t, strings.Index(mu.Del, "<name> <is> <something-else> ."), -1)

	require.NotNil(t, gq)
	require.Equal(t, gq.XID, "tomhanks")
	require.Equal(t, childAttrs(gq), []string{"name", "hometown"})
}
开发者ID:dgraph-io,项目名称:dgraph,代码行数:29,代码来源:parser_test.go


示例6: TestReferencePolicyConfigurationNamespaces

func TestReferencePolicyConfigurationNamespaces(t *testing.T) {
	ref, tmpDir := refToTempOCI(t)
	defer os.RemoveAll(tmpDir)
	// We don't really know enough to make a full equality test here.
	ns := ref.PolicyConfigurationNamespaces()
	require.NotNil(t, ns)
	assert.True(t, len(ns) >= 2)
	assert.Equal(t, tmpDir, ns[0])
	assert.Equal(t, filepath.Dir(tmpDir), ns[1])

	// Test with a known path which should exist. Test just one non-canonical
	// path, the various other cases are tested in explicitfilepath.ResolvePathToFullyExplicit.
	//
	// It would be nice to test a deeper hierarchy, but it is not obvious what
	// deeper path is always available in the various distros, AND is not likely
	// to contains a symbolic link.
	for _, path := range []string{"/etc/skel", "/etc/skel/./."} {
		_, err := os.Lstat(path)
		require.NoError(t, err)
		ref, err := NewReference(path, "sometag")
		require.NoError(t, err)
		ns := ref.PolicyConfigurationNamespaces()
		require.NotNil(t, ns)
		assert.Equal(t, []string{"/etc/skel", "/etc"}, ns)
	}

	// "/" as a corner case.
	ref, err := NewReference("/", "tag3")
	require.NoError(t, err)
	assert.Equal(t, []string{}, ref.PolicyConfigurationNamespaces())
}
开发者ID:containers,项目名称:image,代码行数:31,代码来源:oci_transport_test.go


示例7: TestContainerStatsToPoints

func TestContainerStatsToPoints(t *testing.T) {
	// Given
	storage, err := createTestStorage()
	require.Nil(t, err)
	require.NotNil(t, storage)

	ref, stats := createTestStats()
	require.Nil(t, err)
	require.NotNil(t, stats)

	// When
	points := storage.containerStatsToPoints(*ref, stats)

	// Then
	assert.NotEmpty(t, points)
	assert.Len(t, points, 10+len(stats.Cpu.Usage.PerCpu))

	assertContainsPointWithValue(t, points, serCpuUsageTotal, stats.Cpu.Usage.Total)
	assertContainsPointWithValue(t, points, serCpuUsageSystem, stats.Cpu.Usage.System)
	assertContainsPointWithValue(t, points, serCpuUsageUser, stats.Cpu.Usage.User)
	assertContainsPointWithValue(t, points, serMemoryUsage, stats.Memory.Usage)
	assertContainsPointWithValue(t, points, serLoadAverage, stats.Cpu.LoadAverage)
	assertContainsPointWithValue(t, points, serMemoryWorkingSet, stats.Memory.WorkingSet)
	assertContainsPointWithValue(t, points, serRxBytes, stats.Network.RxBytes)
	assertContainsPointWithValue(t, points, serRxErrors, stats.Network.RxErrors)
	assertContainsPointWithValue(t, points, serTxBytes, stats.Network.TxBytes)
	assertContainsPointWithValue(t, points, serTxBytes, stats.Network.TxErrors)

	for _, cpu_usage := range stats.Cpu.Usage.PerCpu {
		assertContainsPointWithValue(t, points, serCpuUsagePerCpu, cpu_usage)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:32,代码来源:influxdb_test.go


示例8: TestListWorkItemLinkTypeOK

// TestListWorkItemLinkTypeOK tests if we can find the work item link types
// "test-bug-blocker" and "test-related" in the list of work item link types
func (s *workItemLinkTypeSuite) TestListWorkItemLinkTypeOK() {
	bugBlockerPayload := s.createDemoLinkType("test-bug-blocker")
	_, bugBlockerType := test.CreateWorkItemLinkTypeCreated(s.T(), nil, nil, s.linkTypeCtrl, bugBlockerPayload)
	require.NotNil(s.T(), bugBlockerType)

	relatedPayload := CreateWorkItemLinkType("test-related", workitem.SystemBug, workitem.SystemBug, bugBlockerType.Data.Relationships.LinkCategory.Data.ID)
	_, relatedType := test.CreateWorkItemLinkTypeCreated(s.T(), nil, nil, s.linkTypeCtrl, relatedPayload)
	require.NotNil(s.T(), relatedType)

	// Fetch a single work item link type
	_, linkTypeCollection := test.ListWorkItemLinkTypeOK(s.T(), nil, nil, s.linkTypeCtrl)
	require.NotNil(s.T(), linkTypeCollection)
	require.Nil(s.T(), linkTypeCollection.Validate())
	// Check the number of found work item link types
	require.NotNil(s.T(), linkTypeCollection.Data)
	require.Condition(s.T(), func() bool {
		return (len(linkTypeCollection.Data) >= 2)
	}, "At least two work item link types must exist (bug-blocker and related), but only %d exist.", len(linkTypeCollection.Data))
	// Search for the work item types that must exist at minimum
	toBeFound := 2
	for i := 0; i < len(linkTypeCollection.Data) && toBeFound > 0; i++ {
		if *linkTypeCollection.Data[i].Attributes.Name == "test-bug-blocker" || *linkTypeCollection.Data[i].Attributes.Name == "test-related" {
			s.T().Log("Found work item link type in collection: ", *linkTypeCollection.Data[i].Attributes.Name)
			toBeFound--
		}
	}
	require.Exactly(s.T(), 0, toBeFound, "Not all required work item link types (bug-blocker and related) where found.")

	// Check that the link categories are included in the response in the "included" array
	require.Len(s.T(), linkTypeCollection.Included, 1, "The work item link type should include it's work item link category.")
	categoryData, ok := linkTypeCollection.Included[0].(*app.WorkItemLinkCategoryData)
	require.True(s.T(), ok)
	require.Equal(s.T(), "test-user", *categoryData.Attributes.Name, "The work item link type's category should have the name 'test-user'.")
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:36,代码来源:work-item-link-type-blackbox_test.go


示例9: SetupSuite

// The SetupSuite method will run before the tests in the suite are run.
// It sets up a database connection for all the tests in this suite without polluting global space.
func (s *workItemLinkTypeSuite) SetupSuite() {
	var err error

	if err = configuration.Setup(""); err != nil {
		panic(fmt.Errorf("Failed to setup the configuration: %s", err.Error()))
	}

	s.db, err = gorm.Open("postgres", configuration.GetPostgresConfigString())

	if err != nil {
		panic("Failed to connect database: " + err.Error())
	}

	// Make sure the database is populated with the correct types (e.g. bug etc.)
	if err := models.Transactional(DB, func(tx *gorm.DB) error {
		return migration.PopulateCommonTypes(context.Background(), tx, workitem.NewWorkItemTypeRepository(tx))
	}); err != nil {
		panic(err.Error())
	}

	svc := goa.New("workItemLinkTypeSuite-Service")
	require.NotNil(s.T(), svc)
	s.linkTypeCtrl = NewWorkItemLinkTypeController(svc, gormapplication.NewGormDB(DB))
	require.NotNil(s.T(), s.linkTypeCtrl)
	s.linkCatCtrl = NewWorkItemLinkCategoryController(svc, gormapplication.NewGormDB(DB))
	require.NotNil(s.T(), s.linkCatCtrl)
	//	s.typeCtrl = NewWorkitemtypeController(svc, gormapplication.NewGormDB(DB))
	//	require.NotNil(s.T(), s.typeCtrl)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:31,代码来源:work-item-link-type-blackbox_test.go


示例10: TestManifestBuildDPNIdentifierEvent

func TestManifestBuildDPNIdentifierEvent(t *testing.T) {
	nsqMessage := testutil.MakeNsqMessage("999")
	manifest := models.NewDPNIngestManifest(nsqMessage)
	manifest.StorageURL = "https://example.com/my_bag.tar"

	// Should give error, since DPNBag is nil
	event, err := manifest.BuildDPNIdentifierEvent()
	require.NotNil(t, err)

	manifest.DPNBag = testutil.MakeDPNBag()
	event, err = manifest.BuildDPNIdentifierEvent()
	require.Nil(t, err)
	require.NotNil(t, event)

	assert.True(t, util.LooksLikeUUID(event.Identifier))
	assert.Equal(t, constants.EventIdentifierAssignment, event.EventType)
	assert.False(t, event.DateTime.IsZero())
	assert.Equal(t, "Item assigned DPN UUID", event.Detail)
	assert.Equal(t, constants.StatusSuccess, event.Outcome)
	assert.Equal(t, manifest.DPNBag.UUID, event.OutcomeDetail)
	assert.Equal(t, "APTrust exchange using Satori go.uuid", event.Object)
	assert.Equal(t, "https://github.com/satori/go.uuid", event.Agent)
	assert.True(t, strings.Contains(event.OutcomeInformation, manifest.DPNBag.UUID))
	assert.Equal(t, manifest.DPNBag.LocalId, event.IntellectualObjectIdentifier)
}
开发者ID:APTrust,项目名称:exchange,代码行数:25,代码来源:dpn_ingest_manifest_test.go


示例11: TestCreateLoadWITWithList

func (s *workItemTypeRepoBlackBoxTest) TestCreateLoadWITWithList() {
	bt := "string"
	wit, err := s.repo.Create(context.Background(), nil, "foo_bar", map[string]app.FieldDefinition{
		"foo": {
			Required: true,
			Type: &app.FieldType{
				ComponentType: &bt,
				Kind:          string(workitem.KindList),
			},
		},
	})
	assert.Nil(s.T(), err)
	assert.NotNil(s.T(), wit)

	wit3, err := s.repo.Create(context.Background(), nil, "foo_bar", map[string]app.FieldDefinition{})
	assert.IsType(s.T(), errors.BadParameterError{}, errs.Cause(err))
	assert.Nil(s.T(), wit3)

	wit2, err := s.repo.Load(context.Background(), "foo_bar")
	assert.Nil(s.T(), err)
	require.NotNil(s.T(), wit2)
	field := wit2.Fields["foo"]
	require.NotNil(s.T(), field)
	assert.Equal(s.T(), string(workitem.KindList), field.Type.Kind)
	assert.Equal(s.T(), true, field.Required)
	assert.Nil(s.T(), field.Type.BaseType)
	assert.Nil(s.T(), field.Type.Values)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:28,代码来源:workitemtype_repository_blackbox_test.go


示例12: TestManifestBuildReplicationTransfer

func TestManifestBuildReplicationTransfer(t *testing.T) {
	nsqMessage := testutil.MakeNsqMessage("999")
	manifest := models.NewDPNIngestManifest(nsqMessage)
	fromNode := "aptrust"
	toNode := "chron"
	link := "[email protected]:outbound/1234567.tar"
	xfer, err := manifest.BuildReplicationTransfer(fromNode, toNode, link)
	// No DPNBag attached to manifest. Should get error.
	require.NotNil(t, err)

	manifest.DPNBag = testutil.MakeDPNBag()
	xfer, err = manifest.BuildReplicationTransfer(fromNode, toNode, link)
	require.Nil(t, err)
	require.NotNil(t, xfer)

	assert.Equal(t, fromNode, xfer.FromNode)
	assert.Equal(t, toNode, xfer.ToNode)
	assert.Equal(t, manifest.DPNBag.UUID, xfer.Bag)
	assert.True(t, util.LooksLikeUUID(xfer.ReplicationId))

	assert.Equal(t, constants.AlgSha256, xfer.FixityAlgorithm)
	assert.Nil(t, xfer.FixityNonce)
	assert.Nil(t, xfer.FixityValue)
	assert.Equal(t, "rsync", xfer.Protocol)
	assert.Equal(t, link, xfer.Link)
	assert.False(t, xfer.CreatedAt.IsZero())
	assert.False(t, xfer.UpdatedAt.IsZero())
}
开发者ID:APTrust,项目名称:exchange,代码行数:28,代码来源:dpn_ingest_manifest_test.go


示例13: TestBuildIngestChecksums

func TestBuildIngestChecksums(t *testing.T) {
	gf := testutil.MakeGenericFile(0, 0, "test.edu/test_bag/file.txt")
	assert.Equal(t, 0, len(gf.Checksums))
	err := gf.BuildIngestChecksums()
	assert.Nil(t, err)
	assert.Equal(t, 2, len(gf.Checksums))
	md5 := gf.GetChecksumByAlgorithm(constants.AlgMd5)
	sha256 := gf.GetChecksumByAlgorithm(constants.AlgSha256)
	require.NotNil(t, md5)
	require.NotNil(t, sha256)

	assert.Equal(t, md5.GenericFileId, gf.Id)
	assert.Equal(t, constants.AlgMd5, md5.Algorithm)
	assert.False(t, md5.DateTime.IsZero())
	assert.Equal(t, 32, len(md5.Digest))

	assert.Equal(t, sha256.GenericFileId, gf.Id)
	assert.Equal(t, constants.AlgSha256, sha256.Algorithm)
	assert.False(t, sha256.DateTime.IsZero())
	assert.Equal(t, 64, len(sha256.Digest))

	// Calling this function again should not generate new checksums
	// when all the checksums are already present.
	err = gf.BuildIngestChecksums()
	assert.Nil(t, err)
	assert.Equal(t, 2, len(gf.Checksums))
}
开发者ID:APTrust,项目名称:exchange,代码行数:27,代码来源:generic_file_test.go


示例14: TestGenerate

func TestGenerate(t *testing.T) {
	cg := HMACSHAEnigma{
		GlobalSecret: []byte("12345678901234567890"),
	}

	token, signature, err := cg.Generate([]byte("09876543210987654321"))
	require.Nil(t, err, "%s", err)
	require.NotEmpty(t, token)
	require.NotEmpty(t, signature)
	t.Logf("Token: %s\n Signature: %s", token, signature)

	validateSignature, err := cg.Validate([]byte("09876543210987654321"), token)
	require.Nil(t, err, "%s", err)
	assert.Equal(t, signature, validateSignature)

	_, err = cg.Validate([]byte("bar"), token)
	require.NotNil(t, err, "%s", err)

	_, err = cg.Validate([]byte("baz"), token)
	require.NotNil(t, err, "%s", err)

	cg.GlobalSecret = []byte("baz")
	_, err = cg.Validate([]byte("bar"), token)
	require.NotNil(t, err, "%s", err)
}
开发者ID:jesseward,项目名称:fosite,代码行数:25,代码来源:hmacsha_test.go


示例15: TestRefreshOperations

func TestRefreshOperations(t *testing.T) {
	client := &osin.DefaultClient{Id: "4", Secret: "secret", RedirectUri: "http://localhost/", UserData: ""}
	type test struct {
		access *osin.AccessData
	}

	for k, c := range []*test{
		{
			access: &osin.AccessData{
				Client: client,
				AuthorizeData: &osin.AuthorizeData{
					Client:      client,
					Code:        uuid.New(),
					ExpiresIn:   int32(60),
					Scope:       "scope",
					RedirectUri: "http://localhost/",
					State:       "state",
					CreatedAt:   time.Now().Round(time.Second),
					UserData:    userDataMock,
				},
				AccessData:   nil,
				AccessToken:  uuid.New(),
				RefreshToken: uuid.New(),
				ExpiresIn:    int32(60),
				Scope:        "scope",
				RedirectUri:  "https://localhost/",
				CreatedAt:    time.Now().Round(time.Second),
				UserData:     userDataMock,
			},
		},
	} {
		createClient(t, store, client)
		require.Nil(t, store.SaveAuthorize(c.access.AuthorizeData), "Case %d", k)
		require.Nil(t, store.SaveAccess(c.access), "Case %d", k)

		result, err := store.LoadRefresh(c.access.RefreshToken)
		require.Nil(t, err)
		require.Equal(t, c.access.CreatedAt.Unix(), result.CreatedAt.Unix())
		require.Equal(t, c.access.AuthorizeData.CreatedAt.Unix(), result.AuthorizeData.CreatedAt.Unix())
		c.access.CreatedAt = result.CreatedAt
		c.access.AuthorizeData.CreatedAt = result.AuthorizeData.CreatedAt
		require.Equal(t, c.access, result, "Case %d", k)

		require.Nil(t, store.RemoveRefresh(c.access.RefreshToken))
		_, err = store.LoadRefresh(c.access.RefreshToken)

		require.NotNil(t, err, "Case %d", k)
		require.Nil(t, store.RemoveAccess(c.access.AccessToken), "Case %d", k)
		require.Nil(t, store.SaveAccess(c.access), "Case %d", k)

		_, err = store.LoadRefresh(c.access.RefreshToken)
		require.Nil(t, err, "Case %d", k)

		require.Nil(t, store.RemoveAccess(c.access.AccessToken), "Case %d", k)
		_, err = store.LoadRefresh(c.access.RefreshToken)
		require.NotNil(t, err, "Case %d", k)

	}
	removeClient(t, store, client)
}
开发者ID:bagocius,项目名称:osin-storage,代码行数:60,代码来源:postgres_test.go


示例16: TestGenerate

func TestGenerate(t *testing.T) {
	cg := HMACSHAEnigma{
		GlobalSecret: []byte("12345678901234567890"),
	}

	challenge, err := cg.GenerateChallenge([]byte("09876543210987654321"))
	require.Nil(t, err, "%s", err)
	require.NotNil(t, challenge)
	t.Logf("%s.%s", challenge.Key, challenge.Signature)

	err = cg.ValidateChallenge([]byte("09876543210987654321"), challenge)
	require.Nil(t, err, "%s", err)

	challenge.FromString(challenge.String())

	err = cg.ValidateChallenge([]byte("09876543210987654321"), challenge)
	require.Nil(t, err, "%s", err)

	err = cg.ValidateChallenge([]byte("bar"), challenge)
	require.NotNil(t, err, "%s", err)

	err = cg.ValidateChallenge([]byte("baz"), challenge)
	require.NotNil(t, err, "%s", err)

	cg.GlobalSecret = []byte("baz")
	err = cg.ValidateChallenge([]byte("bar"), challenge)
	require.NotNil(t, err, "%s", err)
}
开发者ID:ajayk,项目名称:fosite,代码行数:28,代码来源:hmacsha_test.go


示例17: TestDockerFilesystemStats

func TestDockerFilesystemStats(t *testing.T) {
	fm := framework.New(t)
	defer fm.Cleanup()

	storageDriver := fm.Docker().StorageDriver()
	switch storageDriver {
	case framework.Aufs:
	case framework.Overlay:
	default:
		t.Skip("skipping filesystem stats test")
	}
	// Wait for the container to show up.
	containerId := fm.Docker().RunBusybox("/bin/sh", "-c", "dd if=/dev/zero of=/file count=1 bs=1M & ping www.google.com")
	waitForContainer(containerId, fm)
	time.Sleep(time.Minute)
	request := &v2.RequestOptions{
		IdType: v2.TypeDocker,
		Count:  1,
	}
	containerInfo, err := fm.Cadvisor().ClientV2().Stats(containerId, request)
	time.Sleep(time.Minute)
	require.NoError(t, err)
	require.True(t, len(containerInfo) == 1)
	var info v2.ContainerInfo
	for _, cInfo := range containerInfo {
		info = cInfo
	}
	sanityCheckV2(containerId, info, t)
	require.NotNil(t, info.Stats[0].Filesystem.BaseUsageBytes)
	assert.True(t, *info.Stats[0].Filesystem.BaseUsageBytes > (1<<6), "expected base fs usage to be greater than 1MB")
	require.NotNil(t, info.Stats[0].Filesystem.TotalUsageBytes)
	assert.True(t, *info.Stats[0].Filesystem.TotalUsageBytes > (1<<6), "expected total fs usage to be greater than 1MB")
}
开发者ID:kk4728,项目名称:cadvisor,代码行数:33,代码来源:docker_test.go


示例18: TestCreateFeed

func TestCreateFeed(t *testing.T) {
	feedTitle := fmt.Sprintf("test-feed-%d", rand.Intn(1000000000))
	url := _url("/feeds/" + feedTitle)

	res, err := http.Get(url)
	require.Nil(t, err)
	require.Equal(t, res.StatusCode, 404)

	entryStr := "<entry><title>foo</title><content>bar</content></entry>"
	buf := bytes.NewBufferString(entryStr)
	res, err = http.Post(url, "application/atom+xml", buf)
	require.Nil(t, err)
	require.Equal(t, res.StatusCode, 201, "created feed")

	res, err = http.Get(url)
	require.Nil(t, err)
	require.Equal(t, res.StatusCode, 200, "got feed")

	feed, err := atom.DecodeFeed(res.Body)
	require.Nil(t, err, "parsed feed")
	assert.Equal(t, feed.Title.Raw, feedTitle, "feed title")
	require.NotNil(t, feed.Updated, "feed.updated")
	assert.Regexp(t, timeRe, *feed.Updated, "feed.updated")

	require.Equal(t, len(feed.Entries), 1, "got 1 entry")
	entry := feed.Entries[0]
	assert.Equal(t, entry.Content.Raw, "bar", "entry content")
	require.NotNil(t, entry.Updated, "entry.updated")
	assert.Regexp(t, timeRe, *entry.Updated, "entry.updated")
}
开发者ID:ironcamel,项目名称:go.atompub,代码行数:30,代码来源:atompub_test.go


示例19: TestParseGenericTimestamp

func TestParseGenericTimestamp(t *testing.T) {
	p := &Parser{
		Patterns: []string{`\[%{HTTPDATE:ts:ts}\] response_time=%{POSINT:response_time:int} mymetric=%{NUMBER:metric:float}`},
	}
	assert.NoError(t, p.Compile())

	metricA, err := p.ParseLine(`[09/Jun/2016:03:37:03 +0000] response_time=20821 mymetric=10890.645`)
	require.NotNil(t, metricA)
	assert.NoError(t, err)
	assert.Equal(t,
		map[string]interface{}{
			"response_time": int64(20821),
			"metric":        float64(10890.645),
		},
		metricA.Fields())
	assert.Equal(t, map[string]string{}, metricA.Tags())
	assert.Equal(t, time.Unix(1465443423, 0).UTC(), metricA.Time().UTC())

	metricB, err := p.ParseLine(`[09/Jun/2016:03:37:04 +0000] response_time=20821 mymetric=10890.645`)
	require.NotNil(t, metricB)
	assert.NoError(t, err)
	assert.Equal(t,
		map[string]interface{}{
			"response_time": int64(20821),
			"metric":        float64(10890.645),
		},
		metricB.Fields())
	assert.Equal(t, map[string]string{}, metricB.Tags())
	assert.Equal(t, time.Unix(1465443424, 0).UTC(), metricB.Time().UTC())
}
开发者ID:li-ang,项目名称:telegraf,代码行数:30,代码来源:grok_test.go


示例20: snapEnumerate

func snapEnumerate(t *testing.T, ctx *Context) {
	fmt.Println("snapEnumerate")

	snaps, err := ctx.SnapEnumerate(nil, nil)
	require.NoError(t, err, "Failed in snapEnumerate")
	require.NotNil(t, snaps, "Nil snaps")
	require.Equal(t, 1, len(snaps), "Expect 1 snaps actual %v snaps", len(snaps))
	require.Equal(t, snaps[0].Id, ctx.snapID, "Expect snapID %v actual %v", ctx.snapID, snaps[0].Id)
	labels := snaps[0].Locator.VolumeLabels

	snaps, err = ctx.SnapEnumerate([]string{ctx.volID}, nil)
	require.NoError(t, err, "Failed in snapEnumerate")
	require.NotNil(t, snaps, "Nil snaps")
	require.Equal(t, len(snaps), 1, "Expect 1 snap actual %v snaps", len(snaps))
	require.Equal(t, snaps[0].Id, ctx.snapID, "Expect snapID %v actual %v", ctx.snapID, snaps[0].Id)

	snaps, err = ctx.SnapEnumerate([]string{string("shouldNotExist")}, nil)
	require.Equal(t, len(snaps), 0, "Expect 0 snap actual %v snaps", len(snaps))

	snaps, err = ctx.SnapEnumerate(nil, labels)
	require.NoError(t, err, "Failed in snapEnumerate")
	require.NotNil(t, snaps, "Nil snaps")
	require.Equal(t, len(snaps), 1, "Expect 1 snap actual %v snaps", len(snaps))
	require.Equal(t, snaps[0].Id, ctx.snapID, "Expect snapID %v actual %v", ctx.snapID, snaps[0].Id)
}
开发者ID:ModelRocket,项目名称:openstorage,代码行数:25,代码来源:driver.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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