本文整理汇总了Golang中github.com/stretchr/testify/assert.Empty函数的典型用法代码示例。如果您正苦于以下问题:Golang Empty函数的具体用法?Golang Empty怎么用?Golang Empty使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Empty函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestNewDispatch
func TestNewDispatch(t *testing.T) {
bot := getMockBot()
assert.Empty(t, bot.dispatch.commands, "A new bot should have no commands.")
assert.Nil(t, bot.dispatch.defaultHandler, "Default handler should be nil.")
assert.Empty(t, bot.commandNames, "No command names should be stored on creation.")
assert.Empty(t, bot.patterns, "Patterns array should be empty on creation.")
}
开发者ID:ereyes01,项目名称:victor,代码行数:7,代码来源:dispatch_test.go
示例2: TestPager
func TestPager(t *testing.T) {
pages := createTestPages(21)
groups, _ := pages.GroupBy("Weight", "desc")
urlFactory := func(page int) string {
return fmt.Sprintf("page/%d/", page)
}
_, err := newPaginatorFromPages(pages, -1, urlFactory)
assert.NotNil(t, err)
_, err = newPaginatorFromPageGroups(groups, -1, urlFactory)
assert.NotNil(t, err)
pag, err := newPaginatorFromPages(pages, 5, urlFactory)
assert.Nil(t, err)
doTestPages(t, pag)
first := pag.Pagers()[0].First()
assert.NotEmpty(t, first.Pages())
assert.Empty(t, first.PageGroups())
pag, err = newPaginatorFromPageGroups(groups, 5, urlFactory)
assert.Nil(t, err)
doTestPages(t, pag)
first = pag.Pagers()[0].First()
assert.NotEmpty(t, first.PageGroups())
assert.Empty(t, first.Pages())
}
开发者ID:tarsisazevedo,项目名称:hugo,代码行数:29,代码来源:pagination_test.go
示例3: TestChangeTargetMetaDoesntFallbackIfPrefixError
// If applying a change fails due to a prefix error, it does not fall back
// on the parent.
func TestChangeTargetMetaDoesntFallbackIfPrefixError(t *testing.T) {
repo, cs, err := testutils.EmptyRepo("docker.com/notary")
assert.NoError(t, err)
newKey, err := cs.Create("targets/level1", data.ED25519Key)
assert.NoError(t, err)
r, err := data.NewRole("targets/level1", 1, []string{newKey.ID()},
[]string{"pathprefix"})
assert.NoError(t, err)
repo.UpdateDelegations(r, []data.PublicKey{newKey})
hash := sha256.Sum256([]byte{})
f := &data.FileMeta{
Length: 1,
Hashes: map[string][]byte{
"sha256": hash[:],
},
}
fjson, err := json.Marshal(f)
assert.NoError(t, err)
err = changeTargetMeta(repo, &changelist.TufChange{
Actn: changelist.ActionCreate,
Role: "targets/level1",
ChangeType: "target",
ChangePath: "notPathPrefix",
Data: fjson,
})
assert.Error(t, err)
// no target in targets or targets/latest
assert.Empty(t, repo.Targets[data.CanonicalTargetsRole].Signed.Targets)
assert.Empty(t, repo.Targets["targets/level1"].Signed.Targets)
}
开发者ID:NathanMcCauley,项目名称:notary,代码行数:37,代码来源:helpers_test.go
示例4: TestGC
func TestGC(t *testing.T) {
var podEvictedCount int
var containerEvictedCount int
cache := NewCache(time.Millisecond, time.Second)
cache.AddCacheListener(CacheListener{
PodEvicted: func(namespace string, name string) {
podEvictedCount += 1
},
FreeContainerEvicted: func(hostname string, name string) {
containerEvictedCount += 1
},
})
var (
pods []source_api.Pod
containers []source_api.Container
)
f := fuzz.New().NumElements(2, 10).NilChance(0)
f.Fuzz(&pods)
f.Fuzz(&containers)
assert := assert.New(t)
assert.NoError(cache.StorePods(pods))
assert.NoError(cache.StoreContainers(containers))
zeroTime := time.Time{}
assert.NotEmpty(cache.GetFreeContainers(zeroTime, zeroTime))
assert.NotEmpty(cache.GetPods(zeroTime, zeroTime))
// Expect all data to be deleted after 2 seconds.
time.Sleep(10 * time.Second)
assert.Empty(cache.GetFreeContainers(zeroTime, zeroTime))
assert.Empty(cache.GetPods(zeroTime, zeroTime))
assert.Equal(len(pods), podEvictedCount)
assert.Equal(len(containers), containerEvictedCount)
}
开发者ID:AlbertZheng,项目名称:heapster,代码行数:35,代码来源:cache_impl_test.go
示例5: TestTimeValueSlice
func TestTimeValueSlice(t *testing.T) {
for idx, in := range testCasesTimeValueSlice {
if in == nil {
continue
}
out := aws.TimeValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := aws.TimeSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
开发者ID:gunosy,项目名称:aws-sdk-go,代码行数:26,代码来源:convutil_test.go
示例6: TestNewConfigWithKeys
func TestNewConfigWithKeys(t *testing.T) {
assert := assert.New(t)
var conf Config
conf = NewConfigWithKeys(Keys{
AccessKey: "access",
SecretKey: "secret",
})
assert.NotNil(conf.Config)
assert.NotNil(conf.Config.Credentials)
assert.Empty(conf.Config.Region)
assert.Empty(conf.Config.Endpoint)
conf = NewConfigWithKeys(Keys{
AccessKey: "access",
SecretKey: "secret",
Region: "region",
Endpoint: "endpoint",
})
assert.NotNil(conf.Config)
assert.NotNil(conf.Config.Credentials)
assert.Equal("region", conf.Config.Region)
assert.Equal("endpoint", conf.Config.Endpoint)
}
开发者ID:cnry,项目名称:aws-sdk-go-wrapper,代码行数:25,代码来源:auth_test.go
示例7: TestRouterBuilder
func TestRouterBuilder(t *testing.T) {
spec, api := petstore.NewAPI(t)
assert.Len(t, spec.RequiredConsumes(), 3)
assert.Len(t, spec.RequiredProduces(), 5)
assert.Len(t, spec.OperationIDs(), 4)
// context := NewContext(spec, api)
builder := petAPIRouterBuilder(spec, api)
getRecords := builder.records["GET"]
postRecords := builder.records["POST"]
deleteRecords := builder.records["DELETE"]
assert.Len(t, getRecords, 2)
assert.Len(t, postRecords, 1)
assert.Len(t, deleteRecords, 1)
assert.Empty(t, builder.records["PATCH"])
assert.Empty(t, builder.records["OPTIONS"])
assert.Empty(t, builder.records["HEAD"])
assert.Empty(t, builder.records["PUT"])
rec := postRecords[0]
assert.Equal(t, rec.Key, "/pets")
val := rec.Value.(*routeEntry)
assert.Len(t, val.Consumers, 3)
assert.Len(t, val.Producers, 5)
assert.Len(t, val.Consumes, 3)
assert.Len(t, val.Produces, 5)
assert.Len(t, val.Parameters, 1)
}
开发者ID:hartsock,项目名称:go-swagger,代码行数:32,代码来源:router_test.go
示例8: TestCommand
func TestCommand(t *testing.T) {
t.Parallel()
assert := assert.New(t)
c := Command(good1)
res, err := c.Value()
assert.Equal("values_test.go", res)
assert.NoError(err)
c = Command(bad)
res, err = c.Value()
assert.Empty(res)
assert.Equal(`failed to execute "false": "" (exit status 1)`, err.Error())
c = Command(missing)
res, err = c.Value()
assert.Empty(res)
assert.Equal(`failed to execute "no_such_binary_exists": /bin/bash: no_such_binary_exists: command not found (exit status 127)`, err.Error())
}
开发者ID:inka,项目名称:tacks,代码行数:25,代码来源:command_test.go
示例9: TestFailedRetrieveCredentials
func TestFailedRetrieveCredentials(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(400)
encoder := json.NewEncoder(w)
err := encoder.Encode(map[string]interface{}{
"Code": "Error",
"Message": "Message",
})
if err != nil {
fmt.Println("failed to write error", err)
}
}))
client := endpointcreds.NewProviderClient(*unit.Session.Config, unit.Session.Handlers, server.URL)
creds, err := client.Retrieve()
assert.Error(t, err)
aerr := err.(awserr.Error)
assert.Equal(t, "CredentialsEndpointError", aerr.Code())
assert.Equal(t, "failed to load credentials", aerr.Message())
aerr = aerr.OrigErr().(awserr.Error)
assert.Equal(t, "Error", aerr.Code())
assert.Equal(t, "Message", aerr.Message())
assert.Empty(t, creds.AccessKeyID)
assert.Empty(t, creds.SecretAccessKey)
assert.Empty(t, creds.SessionToken)
assert.True(t, client.IsExpired())
}
开发者ID:ColourboxDevelopment,项目名称:aws-sdk-go,代码行数:32,代码来源:provider_test.go
示例10: TestLocksome
func TestLocksome(t *testing.T) {
j := setUpTest(t, "TestLocksome")
defer tearDownTest(t, j)
ok, msg, err := j.Lock("id", 0,
[]interface{}{[]interface{}{"foo"}})
if assert.NoError(t, err) {
assert.True(t, ok)
assert.Empty(t, msg)
}
locked, msg, err := j.Locksome("id", 0, []interface{}{
[]interface{}{"foo"},
[]interface{}{"bar"},
[]interface{}{"baz"},
})
if assert.NoError(t, err) {
assert.Empty(t, msg)
assert.Equal(t, [][]interface{}{
nil,
[]interface{}{"bar"},
[]interface{}{"baz"},
}, locked)
}
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:25,代码来源:locks_test.go
示例11: TestClearSession
func TestClearSession(t *testing.T) {
withFakeHome(t, func() {
repo := NewConfigurationDiskRepository()
config, err := repo.Get()
assert.NoError(t, err)
config.Target = "http://api.example.com"
config.RefreshToken = "some old refresh token"
config.AccessToken = "some old access token"
org := cf.OrganizationFields{}
org.Name = "my-org"
space := cf.SpaceFields{}
space.Name = "my-space"
repo.Save()
err = repo.ClearSession()
assert.NoError(t, err)
repo.Save()
savedConfig, err := repo.Get()
assert.NoError(t, err)
assert.Equal(t, savedConfig.Target, "http://api.example.com")
assert.Empty(t, savedConfig.AccessToken)
assert.Empty(t, savedConfig.RefreshToken)
assert.Equal(t, savedConfig.OrganizationFields, cf.OrganizationFields{})
assert.Equal(t, savedConfig.SpaceFields, cf.SpaceFields{})
})
}
开发者ID:nsnt,项目名称:cli,代码行数:29,代码来源:repository_test.go
示例12: TestUnlockSanity
func TestUnlockSanity(t *testing.T) {
j := setUpTest(t, "TestUnlockSanity")
defer tearDownTest(t, j)
keys := []interface{}{[]interface{}{"foo"}, []interface{}{"bar"}}
ok, msg, err := j.Lock("id", 0, keys)
if assert.NoError(t, err) {
assert.True(t, ok)
assert.Empty(t, msg)
}
// Should not be able to unlock something a different locker locked
ok, msg, err = j.Unlock("id2", keys)
if assert.NoError(t, err) {
assert.False(t, ok)
assert.NotEmpty(t, msg)
}
// Should be able to read original lock
lockid, err := j.Readlock(keys)
if assert.NoError(t, err) {
assert.Equal(t, []interface{}{"id", "id"}, lockid)
}
ok, msg, err = j.Unlock("id", keys)
if assert.NoError(t, err) {
assert.True(t, ok)
assert.Empty(t, msg)
}
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:31,代码来源:locks_test.go
示例13: TestPushingAppWhenItDoesNotExistButRouteExists
func TestPushingAppWhenItDoesNotExistButRouteExists(t *testing.T) {
domains := []cf.Domain{
cf.Domain{Name: "foo.cf-app.com", Guid: "foo-domain-guid"},
}
route := cf.Route{Host: "my-new-app"}
domainRepo := &testhelpers.FakeDomainRepository{FindByNameDomain: domains[0]}
routeRepo := &testhelpers.FakeRouteRepository{FindByHostRoute: route}
appRepo := &testhelpers.FakeApplicationRepository{AppByNameErr: true}
stackRepo := &testhelpers.FakeStackRepository{}
fakeStarter := &testhelpers.FakeAppStarter{}
fakeStopper := &testhelpers.FakeAppStopper{}
zipper := &testhelpers.FakeZipper{}
fakeUI := callPush([]string{"--name", "my-new-app"}, fakeStarter, fakeStopper, zipper, appRepo, domainRepo, routeRepo, stackRepo)
assert.Empty(t, routeRepo.CreatedRoute.Host)
assert.Empty(t, routeRepo.CreatedRouteDomain.Guid)
assert.Contains(t, fakeUI.Outputs[2], "my-new-app.foo.cf-app.com")
assert.Equal(t, routeRepo.FindByHostHost, "my-new-app")
assert.Contains(t, fakeUI.Outputs[3], "my-new-app.foo.cf-app.com")
assert.Equal(t, routeRepo.BoundApp.Name, "my-new-app")
assert.Equal(t, routeRepo.BoundRoute.Host, "my-new-app")
assert.Contains(t, fakeUI.Outputs[4], "OK")
}
开发者ID:jbayer,项目名称:cli,代码行数:25,代码来源:push_test.go
示例14: TestCleanupEvents
func TestCleanupEvents(t *testing.T) {
_, server := initServer()
notice := buildSlack(server.URL, map[string]string{"delay_in_sec": "0"})
assert.True(t, notice.debounce)
testEvents := []notices.Event{
notices.Event{
ServiceName: "testService",
Status: storages.DownStatus,
Occurred: time.Now(),
},
notices.Event{
ServiceName: "testService",
Status: storages.UpStatus,
Occurred: time.Now(),
},
}
assert.Empty(t, notice.cleanupEvents(testEvents))
testEvents[0].Status = storages.UpStatus
testEvents[1].Status = storages.DownStatus
assert.Empty(t, notice.cleanupEvents(testEvents))
testEvents[0].Status = storages.DownStatus
testEvents[1].Status = storages.DownStatus
assert.NotEmpty(t, notice.cleanupEvents(testEvents))
testEvents[0].Status = storages.UpStatus
testEvents[1].Status = storages.UpStatus
assert.NotEmpty(t, notice.cleanupEvents(testEvents))
}
开发者ID:pubnative,项目名称:statusboard,代码行数:27,代码来源:slack_test.go
示例15: TestSetupSettingsClearDb
func TestSetupSettingsClearDb(t *testing.T) {
clearDb()
defer clearDb()
var err error
db, err = OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
eventSettings, _ = db.GetEventSettings()
db.CreateTeam(new(Team))
db.CreateMatch(&Match{Type: "qualification"})
db.CreateMatchResult(new(MatchResult))
db.CreateRanking(new(Ranking))
db.CreateAllianceTeam(new(AllianceTeam))
recorder := postHttpResponse("/setup/db/clear", "")
assert.Equal(t, 302, recorder.Code)
teams, _ := db.GetAllTeams()
assert.NotEmpty(t, teams)
matches, _ := db.GetMatchesByType("qualification")
assert.Empty(t, matches)
rankings, _ := db.GetAllRankings()
assert.Empty(t, rankings)
db.CalculateRankings()
assert.Empty(t, rankings)
alliances, _ := db.GetAllAlliances()
assert.Empty(t, alliances)
}
开发者ID:Team254,项目名称:cheesy-arena,代码行数:28,代码来源:setup_settings_test.go
示例16: TestPushingAppWhenItDoesNotExistButRouteExists
func TestPushingAppWhenItDoesNotExistButRouteExists(t *testing.T) {
deps := getPushDependencies()
domain := cf.Domain{}
domain.Name = "foo.cf-app.com"
domain.Guid = "foo-domain-guid"
domain.Shared = true
route := cf.Route{}
route.Guid = "my-route-guid"
route.Host = "my-new-app"
route.Domain = domain.DomainFields
deps.domainRepo.ListSharedDomainsDomains = []cf.Domain{domain}
deps.routeRepo.FindByHostAndDomainRoute = route
deps.appRepo.ReadNotFound = true
ui := callPush(t, []string{"my-new-app"}, deps)
assert.Empty(t, deps.routeRepo.CreatedHost)
assert.Empty(t, deps.routeRepo.CreatedDomainGuid)
assert.Equal(t, deps.routeRepo.FindByHostAndDomainHost, "my-new-app")
assert.Equal(t, deps.routeRepo.BoundAppGuid, "my-new-app-guid")
assert.Equal(t, deps.routeRepo.BoundRouteGuid, "my-route-guid")
testassert.SliceContains(t, ui.Outputs, testassert.Lines{
{"Using", "my-new-app.foo.cf-app.com"},
{"Binding", "my-new-app.foo.cf-app.com"},
{"OK"},
})
}
开发者ID:nsnt,项目名称:cli,代码行数:32,代码来源:push_test.go
示例17: TestUpdateAgent
func TestUpdateAgent(t *testing.T) {
pluginInput := createStubPluginInput()
pluginInput.TargetVersion = ""
context := createStubInstanceContext()
manifest := createStubManifest(pluginInput, context, true, true)
config := contracts.Configuration{}
plugin := &Plugin{}
testCases := []fakeUpdateManager{
{
generateUpdateCmdResult: "-updater -message id value",
generateUpdateCmdError: nil,
downloadManifestResult: manifest,
downloadManifestError: nil,
downloadUpdaterResult: "updater",
downloadUpdaterError: nil,
validateUpdateResult: false,
validateUpdateError: nil,
},
}
pluginInput.TargetVersion = ""
mockCancelFlag := new(task.MockCancelFlag)
util := fakeUtility{}
for _, manager := range testCases {
out := updateAgent(plugin, config, logger, &manager, &util, pluginInput, mockCancelFlag, "", "", time.Now())
assert.Empty(t, out.Stderr)
assert.Empty(t, out.Errors)
}
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:31,代码来源:updateagent_test.go
示例18: TestPassesAllowedAllOrigins
func TestPassesAllowedAllOrigins(t *testing.T) {
router := newTestRouter(Config{
AllowAllOrigins: true,
AllowMethods: []string{" Patch ", "get", "post", "POST"},
AllowHeaders: []string{"Content-type", " testheader "},
ExposeHeaders: []string{"Data2", "x-User2"},
AllowCredentials: false,
MaxAge: 10 * time.Hour,
})
// no CORS request, origin == ""
w := performRequest(router, "GET", "")
assert.Equal(t, w.Body.String(), "get")
assert.Empty(t, w.Header().Get("Access-Control-Allow-Origin"))
assert.Empty(t, w.Header().Get("Access-Control-Allow-Credentials"))
assert.Empty(t, w.Header().Get("Access-Control-Expose-Headers"))
// allowed CORS request
w = performRequest(router, "POST", "example.com")
assert.Equal(t, w.Body.String(), "post")
assert.Equal(t, w.Header().Get("Access-Control-Allow-Origin"), "*")
assert.Equal(t, w.Header().Get("Access-Control-Expose-Headers"), "Data2,X-User2")
assert.Empty(t, w.Header().Get("Access-Control-Allow-Credentials"))
// allowed CORS prefligh request
w = performRequest(router, "OPTIONS", "https://facebook.com")
assert.Equal(t, w.Code, 200)
assert.Equal(t, w.Header().Get("Access-Control-Allow-Origin"), "*")
assert.Equal(t, w.Header().Get("Access-Control-Allow-Methods"), "PATCH,GET,POST")
assert.Equal(t, w.Header().Get("Access-Control-Allow-Headers"), "Content-Type,Testheader")
assert.Equal(t, w.Header().Get("Access-Control-Max-Age"), "36000")
assert.Empty(t, w.Header().Get("Access-Control-Allow-Credentials"))
}
开发者ID:gin-contrib,项目名称:cors,代码行数:33,代码来源:cors_test.go
示例19: TestBitFlush
func TestBitFlush(t *testing.T) {
var err error
buf := new(bytes.Buffer)
w := newBitWriter(buf)
// Empty flush
err = w.Flush()
assert.Nil(t, err)
assert.Empty(t, buf.Bytes())
// Flush with one 0 bit
buf.Reset()
w.WriteBitString("0")
assert.Empty(t, buf.Bytes())
err = w.Flush()
assert.Nil(t, err)
assert.Equal(t, []byte{0x00}, buf.Bytes())
// Flush with 2 bytes
buf.Reset()
w.WriteBitString("01100101010")
assert.Equal(t, []byte{0x65}, buf.Bytes())
err = w.Flush()
assert.Nil(t, err)
assert.Equal(t, []byte{0x65, 0x40}, buf.Bytes())
// Test double flush
err = w.Flush()
assert.Nil(t, err)
assert.Equal(t, []byte{0x65, 0x40}, buf.Bytes())
}
开发者ID:sjeff83,项目名称:hzip,代码行数:30,代码来源:bits_test.go
示例20: TestBoltDatabase_FindNames
func TestBoltDatabase_FindNames(t *testing.T) {
db := NewBoltDatabase("test9.db")
defer db.Release()
defer os.Remove("test9.db")
config := BasketConfig{Capacity: 5}
for i := 0; i < 35; i++ {
db.Create(fmt.Sprintf("test%v", i), config)
}
res1 := db.FindNames("test2", 20, 0)
assert.False(t, res1.HasMore, "no more names are expected")
assert.Len(t, res1.Names, 11, "wrong number of found names")
for _, name := range res1.Names {
assert.Contains(t, name, "test2", "invalid name among search results")
}
res2 := db.FindNames("test1", 5, 0)
assert.True(t, res2.HasMore, "more names are expected")
assert.Len(t, res2.Names, 5, "wrong number of found names")
// Corner cases
assert.Len(t, db.FindNames("test1", 5, 10).Names, 1, "wrong number of returned names")
assert.Empty(t, db.FindNames("test2", 5, 20).Names, "names in this page are not expected")
assert.False(t, db.FindNames("test3", 5, 6).HasMore, "no more names are expected")
assert.False(t, db.FindNames("abc", 5, 0).HasMore, "no more names are expected")
assert.Empty(t, db.FindNames("xyz", 5, 0).Names, "names are not expected")
}
开发者ID:darklynx,项目名称:request-baskets,代码行数:28,代码来源:baskets_bolt_test.go
注:本文中的github.com/stretchr/testify/assert.Empty函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论