本文整理汇总了Golang中github.com/stretchr/testify/require.NotNil函数的典型用法代码示例。如果您正苦于以下问题:Golang NotNil函数的具体用法?Golang NotNil怎么用?Golang NotNil使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NotNil函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
}
}
示例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)
})
}
示例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)
}
示例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.")
}
示例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"})
}
示例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())
}
示例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)
}
}
示例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'.")
}
示例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)
}
示例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)
}
示例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)
}
示例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())
}
示例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))
}
示例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)
}
示例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)
}