本文整理汇总了Golang中github.com/stretchr/testify/assert.Len函数的典型用法代码示例。如果您正苦于以下问题:Golang Len函数的具体用法?Golang Len怎么用?Golang Len使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Len函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestLinesWithSimilarAngle
func TestLinesWithSimilarAngle(t *testing.T) {
examples := []struct {
angle float64
lines []polarLine
similar []polarLine
other []polarLine
}{
{
angle: 0,
lines: []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: 0.5}, polarLine{Theta: -0.49}, polarLine{Theta: -0.5}},
similar: []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: -0.49}},
other: []polarLine{polarLine{Theta: 0.5}, polarLine{Theta: -0.5}},
},
{
angle: 2 * math.Pi,
lines: []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: 0.5}, polarLine{Theta: -0.49}, polarLine{Theta: -0.5}},
similar: []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: -0.49}},
other: []polarLine{polarLine{Theta: 0.5}, polarLine{Theta: -0.5}},
},
{
angle: math.Pi,
lines: []polarLine{polarLine{Theta: math.Pi + 0, Distance: 1}, polarLine{Theta: math.Pi + 0, Distance: 1000}, polarLine{Theta: math.Pi + 0.49}, polarLine{Theta: math.Pi + 0.5}, polarLine{Theta: math.Pi - 0.49}, polarLine{Theta: math.Pi - 0.5}},
similar: []polarLine{polarLine{Theta: math.Pi + 0, Distance: 1}, polarLine{Theta: math.Pi + 0, Distance: 1000}, polarLine{Theta: math.Pi + 0.49}, polarLine{Theta: math.Pi - 0.49}},
other: []polarLine{polarLine{Theta: math.Pi + 0.5}, polarLine{Theta: math.Pi - 0.5}},
},
{
angle: math.Pi,
lines: []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: 0.5}, polarLine{Theta: -0.49}, polarLine{Theta: -0.5}},
similar: []polarLine{},
other: []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: 0.5}, polarLine{Theta: -0.49}, polarLine{Theta: -0.5}},
},
{
angle: 0,
lines: []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: -0.49}},
similar: []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: -0.49}},
other: []polarLine{},
},
}
for _, tt := range examples {
similar, other := linesWithSimilarAngle(tt.lines, tt.angle)
if !assert.Len(t, similar, len(tt.similar)) {
t.Logf("Got:\n%v\nexpecting:\n%v", similar, tt.similar)
t.FailNow()
}
for i, line := range similar {
assert.InDelta(t, tt.similar[i].Theta, line.Theta, thetaDelta)
assert.Equal(t, tt.similar[i].Distance, line.Distance)
}
if !assert.Len(t, other, len(tt.other)) {
t.Logf("Got:\n%v\nexpecting:\n%v", similar, tt.similar)
t.FailNow()
}
for i, line := range other {
assert.InDelta(t, tt.other[i].Theta, line.Theta, thetaDelta)
assert.Equal(t, tt.other[i].Distance, line.Distance)
}
}
}
示例2: TestMultipleGetEmpty
func TestMultipleGetEmpty(t *testing.T) {
q := New(10)
var wg sync.WaitGroup
wg.Add(2)
results := make([][]interface{}, 2)
go func() {
wg.Done()
local, err := q.Get(1)
assert.Nil(t, err)
results[0] = local
wg.Done()
}()
go func() {
wg.Done()
local, err := q.Get(1)
assert.Nil(t, err)
results[1] = local
wg.Done()
}()
wg.Wait()
wg.Add(2)
q.Put(`a`, `b`, `c`)
wg.Wait()
if assert.Len(t, results[0], 1) && assert.Len(t, results[1], 1) {
assert.True(t, (results[0][0] == `a` && results[1][0] == `b`) ||
(results[0][0] == `b` && results[1][0] == `a`),
`The array should be a, b or b, a`)
}
}
示例3: TestCreateControlChannel
func TestCreateControlChannel(t *testing.T) {
node := NewNode()
assert.Len(t, node.controlChannels, 0, "Should be 0 control channels")
node.AddControlChannel()
assert.Len(t, node.controlChannels, 1, "Should be 1 control channels")
fmt.Println("--------------------\n")
}
示例4: TestContextError
func TestContextError(t *testing.T) {
c, _, _ := CreateTestContext()
assert.Empty(t, c.Errors)
c.Error(errors.New("first error"))
assert.Len(t, c.Errors, 1)
assert.Equal(t, c.Errors.String(), "Error #01: first error\n")
c.Error(&Error{
Err: errors.New("second error"),
Meta: "some data 2",
Type: ErrorTypePublic,
})
assert.Len(t, c.Errors, 2)
assert.Equal(t, c.Errors[0].Err, errors.New("first error"))
assert.Nil(t, c.Errors[0].Meta)
assert.Equal(t, c.Errors[0].Type, ErrorTypePrivate)
assert.Equal(t, c.Errors[1].Err, errors.New("second error"))
assert.Equal(t, c.Errors[1].Meta, "some data 2")
assert.Equal(t, c.Errors[1].Type, ErrorTypePublic)
assert.Equal(t, c.Errors.Last(), c.Errors[1])
}
示例5: TestGetPodContainers
//TestGetPodContainers tests the flow of GetPodContainers.
func TestGetPodContainers(t *testing.T) {
var (
cluster = newRealCluster(newTimeStore, time.Minute)
source_cache = cacheFactory()
assert = assert.New(t)
)
// Invocation with empty cluster
res := cluster.GetPodContainers("test", "pod1")
assert.Len(res, 0)
// Populate cluster
assert.NoError(cluster.Update(source_cache))
// Normal Invocation
res = cluster.GetPodContainers("test", "pod1")
assert.Len(res, 2)
// Invocation with non-existant namespace
res = cluster.GetPodContainers("fail", "pod1")
assert.Len(res, 0)
// Invocation with non-existant pod
res = cluster.GetPodContainers("test", "pod5")
assert.Len(res, 0)
}
示例6: TestEmailsService_All
func TestEmailsService_All(t *testing.T) {
setup()
defer tearDown()
link := fmt.Sprintf(`<%s>; rel="next", <%s>; rel="last"`, testURLOf("/user/emails?page=2"), testURLOf("/user/emails?page=3"))
respHeaderParams := map[string]string{"Link": link}
stubGet(t, "/user/emails", "emails", respHeaderParams)
url, _ := EmailUrl.Expand(nil)
allEmails, result := client.Emails(url).All()
assert.False(t, result.HasError())
assert.Len(t, allEmails, 1)
email := allEmails[0]
assert.Equal(t, "[email protected]", email.Email)
assert.Equal(t, true, email.Verified)
assert.Equal(t, true, email.Primary)
assert.Equal(t, testURLStringOf("/user/emails?page=2"), string(*result.NextPage))
assert.Equal(t, testURLStringOf("/user/emails?page=3"), string(*result.LastPage))
nextPageURL, err := result.NextPage.Expand(nil)
assert.NoError(t, err)
allEmails, result = client.Emails(nextPageURL).All()
assert.False(t, result.HasError())
assert.Len(t, allEmails, 1)
}
示例7: TestAddBaseKeysToRoot
// adding a key to a role marks root as dirty as well as the role
func TestAddBaseKeysToRoot(t *testing.T) {
for _, role := range data.BaseRoles {
ed25519 := signed.NewEd25519()
keyDB := keys.NewDB()
repo := initRepo(t, ed25519, keyDB)
key, err := ed25519.Create(role, data.ED25519Key)
assert.NoError(t, err)
assert.Len(t, repo.Root.Signed.Roles[role].KeyIDs, 1)
assert.NoError(t, repo.AddBaseKeys(role, key))
_, ok := repo.Root.Signed.Keys[key.ID()]
assert.True(t, ok)
assert.Len(t, repo.Root.Signed.Roles[role].KeyIDs, 2)
assert.True(t, repo.Root.Dirty)
switch role {
case data.CanonicalSnapshotRole:
assert.True(t, repo.Snapshot.Dirty)
case data.CanonicalTargetsRole:
assert.True(t, repo.Targets[data.CanonicalTargetsRole].Dirty)
case data.CanonicalTimestampRole:
assert.True(t, repo.Timestamp.Dirty)
}
}
}
示例8: TestRunningOutputFlushWhenFull
// Test that running output doesn't flush until it's full when
// FlushBufferWhenFull is set.
func TestRunningOutputFlushWhenFull(t *testing.T) {
conf := &OutputConfig{
Filter: Filter{
IsActive: false,
},
}
m := &mockOutput{}
ro := NewRunningOutput("test", m, conf, 6, 10)
// Fill buffer to 1 under limit
for _, metric := range first5 {
ro.AddMetric(metric)
}
// no flush yet
assert.Len(t, m.Metrics(), 0)
// add one more metric
ro.AddMetric(next5[0])
// now it flushed
assert.Len(t, m.Metrics(), 6)
// add one more metric and write it manually
ro.AddMetric(next5[1])
err := ro.Write()
assert.NoError(t, err)
assert.Len(t, m.Metrics(), 7)
}
示例9: TestUpdateDelegationsRoleThatIsMissingDelegationKey
// A delegation can be created with a role that is missing a signing key, so
// long as UpdateDelegations is called with the key
func TestUpdateDelegationsRoleThatIsMissingDelegationKey(t *testing.T) {
ed25519 := signed.NewEd25519()
keyDB := keys.NewDB()
repo := initRepo(t, ed25519, keyDB)
roleKey, err := ed25519.Create("Invalid Role", data.ED25519Key)
assert.NoError(t, err)
role, err := data.NewRole("targets/role", 1, []string{}, []string{""}, []string{})
assert.NoError(t, err)
// key should get added to role as part of updating the delegation
err = repo.UpdateDelegations(role, data.KeyList{roleKey})
assert.NoError(t, err)
r, ok := repo.Targets[data.CanonicalTargetsRole]
assert.True(t, ok)
assert.Len(t, r.Signed.Delegations.Roles, 1)
assert.Len(t, r.Signed.Delegations.Keys, 1)
keyIDs := r.Signed.Delegations.Roles[0].KeyIDs
assert.Len(t, keyIDs, 1)
assert.Equal(t, roleKey.ID(), keyIDs[0])
assert.True(t, r.Dirty)
// no empty delegation metadata created for new delegation
_, ok = repo.Targets["targets/role"]
assert.False(t, ok, "no targets file should be created for empty delegation")
}
示例10: TestDeleteDelegationsMidSliceRole
func TestDeleteDelegationsMidSliceRole(t *testing.T) {
ed25519 := signed.NewEd25519()
keyDB := keys.NewDB()
repo := initRepo(t, ed25519, keyDB)
testKey, err := ed25519.Create("targets/test", data.ED25519Key)
assert.NoError(t, err)
role, err := data.NewRole("targets/test", 1, []string{}, []string{""}, []string{})
assert.NoError(t, err)
err = repo.UpdateDelegations(role, data.KeyList{testKey})
assert.NoError(t, err)
role2, err := data.NewRole("targets/test2", 1, []string{}, []string{""}, []string{})
assert.NoError(t, err)
err = repo.UpdateDelegations(role2, data.KeyList{testKey})
assert.NoError(t, err)
role3, err := data.NewRole("targets/test3", 1, []string{}, []string{""}, []string{})
assert.NoError(t, err)
err = repo.UpdateDelegations(role3, data.KeyList{testKey})
assert.NoError(t, err)
err = repo.DeleteDelegation(*role2)
assert.NoError(t, err)
r, ok := repo.Targets[data.CanonicalTargetsRole]
assert.True(t, ok)
assert.Len(t, r.Signed.Delegations.Roles, 2)
assert.Len(t, r.Signed.Delegations.Keys, 1)
assert.True(t, r.Dirty)
}
示例11: TestSplitService
func TestSplitService(t *testing.T) {
e := executor{}
tests := []struct {
description string
service string
version string
alias string
alternative string
}{
{"service", "service", "latest", "service", ""},
{"service:version", "service", "version", "service", ""},
{"namespace/service", "namespace/service", "latest", "namespace__service", "namespace-service"},
{"namespace/service:version", "namespace/service", "version", "namespace__service", "namespace-service"},
}
for _, test := range tests {
service, version, linkNames := e.splitServiceAndVersion(test.description)
assert.Equal(t, test.service, service, "for", test.description)
assert.Equal(t, test.version, version, "for", test.description)
assert.Equal(t, test.alias, linkNames[0], "for", test.description)
if test.alternative != "" {
assert.Len(t, linkNames, 2, "for", test.description)
assert.Equal(t, test.alternative, linkNames[1], "for", test.description)
} else {
assert.Len(t, linkNames, 1, "for", test.description)
}
}
}
示例12: TestPutLinesIntoBucketsReuseLineIfBucketsHaveSlightlyDifferent
func TestPutLinesIntoBucketsReuseLineIfBucketsHaveSlightlyDifferent(t *testing.T) {
buckets := map[float64][]angleBucket{
1.0: {angleBucket{0, 2}},
2.0: {angleBucket{1, 3}},
}
lines := []polarLine{
polarLine{Theta: 1},
polarLine{Theta: 1.1},
polarLine{Theta: 2.1},
}
expected := map[float64][]polarLine{
1.0: {polarLine{Theta: 1}, polarLine{Theta: 1.1}},
2.0: {polarLine{Theta: 1}, polarLine{Theta: 1.1}, polarLine{Theta: 2.1}},
}
bucketed := putLinesIntoBuckets(buckets, lines)
assert.Len(t, bucketed, len(expected))
for angle, expected_lines := range expected {
if !assert.Len(t, bucketed[angle], len(expected_lines)) {
t.FailNow()
}
for i, line := range bucketed[angle] {
assert.EqualValues(t, expected_lines[i], line)
}
}
}
示例13: TestPutLinesIntoBuckets
func TestPutLinesIntoBuckets(t *testing.T) {
buckets := map[float64][]angleBucket{
0.0: {angleBucket{-0.1, 0.1}, angleBucket{math.Pi - 0.1, math.Pi + 0.1}},
1.0: {angleBucket{0.9, 1.1}},
}
lines := []polarLine{
polarLine{Theta: 0},
polarLine{Theta: -0.1},
polarLine{Theta: 0.1},
polarLine{Theta: math.Pi},
polarLine{Theta: 1.1},
polarLine{Theta: 100},
polarLine{Theta: -0.11},
polarLine{Theta: 0.11},
}
expected := map[float64][]polarLine{
0.0: {polarLine{Theta: 0}, polarLine{Theta: -0.1}, polarLine{Theta: 0.1}, polarLine{Theta: math.Pi}},
1.0: {polarLine{Theta: 1.1}},
}
bucketed := putLinesIntoBuckets(buckets, lines)
assert.Len(t, bucketed, len(expected))
for angle, expected_lines := range expected {
if !assert.Len(t, bucketed[angle], len(expected_lines)) {
t.FailNow()
}
for i, line := range bucketed[angle] {
assert.EqualValues(t, expected_lines[i], line)
}
}
}
示例14: TestTelegrafParseLine
func TestTelegrafParseLine(t *testing.T) {
s := Telegraf{}
r, err := s.ParseLine("> mem,host=ubuntu available_percent=78.43483331332489,buffered=199602176i,used=1802661888i,used_percent=21.56516668667511 1469886743")
require.NoError(t, err)
assert.Len(t, r.Elements, 4)
for _, line := range r.Elements {
assert.Equal(t, line.Plugin, "telegraf.mem")
validGauges := []string{"mem_available.percent", "mem_buffered", "mem_used", "mem_used.percent"}
sort.Strings(validGauges)
i := sort.SearchStrings(validGauges, line.Gauge)
var gaugeFound = i < len(validGauges) && validGauges[i] == line.Gauge
assert.True(t, gaugeFound, "Valid Gauge Name")
}
r, err = s.ParseLine("> system,host=ubuntu load1=0.11,load15=0.06,load5=0.05,n_cpus=4i,n_users=2i,uptime=7252i 1469891972000000000")
require.NoError(t, err)
assert.Len(t, r.Elements, 6)
for _, line := range r.Elements {
assert.Equal(t, line.Plugin, "telegraf.system")
validGauges := []string{"system_load1", "system_load15", "system_load5", "system_n.cpus", "system_n.users", "system_uptime"}
sort.Strings(validGauges)
i := sort.SearchStrings(validGauges, line.Gauge)
var gaugeFound = i < len(validGauges) && validGauges[i] == line.Gauge
assert.True(t, gaugeFound, "Valid Gauge Name")
}
}
示例15: TestRunningOutputWriteFail
func TestRunningOutputWriteFail(t *testing.T) {
conf := &OutputConfig{
Filter: Filter{
IsActive: false,
},
}
m := &mockOutput{}
m.failWrite = true
ro := NewRunningOutput("test", m, conf, 4, 12)
// Fill buffer to limit twice
for _, metric := range first5 {
ro.AddMetric(metric)
}
for _, metric := range next5 {
ro.AddMetric(metric)
}
// no successful flush yet
assert.Len(t, m.Metrics(), 0)
// manual write fails
err := ro.Write()
require.Error(t, err)
// no successful flush yet
assert.Len(t, m.Metrics(), 0)
m.failWrite = false
err = ro.Write()
require.NoError(t, err)
assert.Len(t, m.Metrics(), 10)
}