本文整理匯總了Golang中github.com/nyarly/testify/assert.Len函數的典型用法代碼示例。如果您正苦於以下問題:Golang Len函數的具體用法?Golang Len怎麽用?Golang Len使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Len函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestModifyResources
func TestModifyResources(t *testing.T) {
assert := assert.New(t)
version := "1.2.3-test"
pair := baseDeployablePair()
pair.Prior.Deployment.SourceID.Version = semv.MustParse(version)
pair.Prior.Deployment.Resources["memory"] = "100"
pair.Post.Deployment.SourceID.Version = semv.MustParse(version)
pair.Post.Deployment.Resources["memory"] = "500"
pair.Post.BuildArtifact.Name = "1.2.3"
mods := make(chan *sous.DeployablePair, 1)
errs := make(chan error, 10)
client := sous.NewDummyRectificationClient()
deployer := NewDeployer(client)
mods <- pair
close(mods)
deployer.RectifyModifies(mods, errs)
close(errs)
for e := range errs {
t.Error(e)
}
assert.Len(client.Created, 0)
if assert.Len(client.Deployed, 1) {
assert.Regexp("1.2.3", client.Deployed[0].ImageName)
assert.Regexp("500", client.Deployed[0].Res["memory"])
}
}
示例2: TestModifyImage
func TestModifyImage(t *testing.T) {
assert := assert.New(t)
sous.Log.Warn.SetOutput(os.Stderr)
Log.Debug.SetOutput(os.Stderr)
before := "1.2.3-test"
after := "2.3.4-new"
pair := baseDeployablePair()
pair.Prior.Deployment.SourceID.Version = semv.MustParse(before)
pair.Post.Deployment.SourceID.Version = semv.MustParse(after)
pair.Post.BuildArtifact.Name = "2.3.4"
mods := make(chan *sous.DeployablePair, 1)
errs := make(chan error, 10)
client := sous.NewDummyRectificationClient()
deployer := NewDeployer(client)
mods <- pair
close(mods)
deployer.RectifyModifies(mods, errs)
close(errs)
for e := range errs {
t.Error(e)
}
assert.Len(client.Created, 0)
if assert.Len(client.Deployed, 1) {
assert.Regexp("2.3.4", client.Deployed[0].ImageName)
}
}
示例3: TestModifyScale
func TestModifyScale(t *testing.T) {
log.SetFlags(log.Flags() | log.Lshortfile)
assert := assert.New(t)
mods := make(chan *sous.DeployablePair, 1)
errs := make(chan error, 10)
pair := baseDeployablePair()
pair.Prior.Deployment.DeployConfig.NumInstances = 12
pair.Post.Deployment.DeployConfig.NumInstances = 24
client := sous.NewDummyRectificationClient()
deployer := NewDeployer(client)
mods <- pair
close(mods)
deployer.RectifyModifies(mods, errs)
close(errs)
for e := range errs {
t.Error(e)
}
assert.Len(client.Deployed, 0)
if assert.Len(client.Created, 1) {
assert.Equal(24, client.Created[0].Count)
}
}
示例4: TestValidateRepairResources
func TestValidateRepairResources(t *testing.T) {
empty := make(Resources)
flaws := empty.Validate()
assert.Len(t, flaws, 3)
flaws, es := RepairAll(flaws)
assert.Len(t, flaws, 0)
assert.Len(t, es, 0)
assert.Equal(t, empty["cpus"], "0.1")
assert.Equal(t, empty["memory"], "100")
assert.Equal(t, empty["ports"], "1")
}
示例5: TestCreates
func TestCreates(t *testing.T) {
assert := assert.New(t)
created := &sous.Deployable{
BuildArtifact: &sous.BuildArtifact{
Type: "docker",
Name: "reqid,0.0.0",
},
Deployment: &sous.Deployment{
SourceID: sous.SourceID{
Location: sous.SourceLocation{
Repo: "reqid",
},
},
DeployConfig: sous.DeployConfig{
NumInstances: 12,
},
Cluster: &sous.Cluster{BaseURL: "cluster"},
ClusterName: "nick",
},
}
crts := make(chan *sous.Deployable, 1)
errs := make(chan error, 10)
client := sous.NewDummyRectificationClient()
deployer := NewDeployer(client)
crts <- created
close(crts)
deployer.RectifyCreates(crts, errs)
close(errs)
for e := range errs {
t.Error(e)
}
if assert.Len(client.Deployed, 1) {
dep := client.Deployed[0]
assert.Equal("cluster", dep.Cluster)
assert.Equal("reqid,0.0.0", dep.ImageName)
}
if assert.Len(client.Created, 1) {
req := client.Created[0]
assert.Equal("cluster", req.Cluster)
assert.Equal("reqid::nick", req.ID)
assert.Equal(12, req.Count)
}
}
示例6: TestDeletes
func TestDeletes(t *testing.T) {
assert := assert.New(t)
deleted := &sous.Deployable{
Deployment: &sous.Deployment{
SourceID: sous.SourceID{
Location: sous.SourceLocation{
Repo: "reqid",
},
},
DeployConfig: sous.DeployConfig{
NumInstances: 12,
},
ClusterName: "",
Cluster: &sous.Cluster{
BaseURL: "cluster",
},
},
}
dels := make(chan *sous.Deployable, 1)
errs := make(chan error, 10)
client := sous.NewDummyRectificationClient()
deployer := NewDeployer(client)
dels <- deleted
close(dels)
deployer.RectifyDeletes(dels, errs)
close(errs)
for e := range errs {
t.Error(e)
}
assert.Len(client.Deployed, 0)
assert.Len(client.Created, 0)
// We no longer expect any deletions; See deployer.RectifySingleDelete.
//expectedDeletions := 1
expectedDeletions := 0
if assert.Len(client.Deleted, expectedDeletions) {
// We no longer expect any deletions; See deployer.RectifySingleDelete.
//req := client.Deleted[0]
//assert.Equal("cluster", req.Cluster)
//assert.Equal("reqid::", req.Reqid)
}
}
示例7: TestRealDiff
func TestRealDiff(t *testing.T) {
log.SetFlags(log.Flags() | log.Lshortfile)
assert := assert.New(t)
intended := NewDeployments()
existing := NewDeployments()
repoOne := "https://github.com/opentable/one"
repoTwo := "https://github.com/opentable/two"
repoThree := "https://github.com/opentable/three"
repoFour := "https://github.com/opentable/four"
intended.MustAdd(makeDepl(repoOne, 1)) //remove
existing.MustAdd(makeDepl(repoTwo, 1)) //same
intended.MustAdd(makeDepl(repoTwo, 1)) //same
existing.MustAdd(makeDepl(repoThree, 1)) //changed
intended.MustAdd(makeDepl(repoThree, 2)) //changed
existing.MustAdd(makeDepl(repoFour, 1)) //create
dc := intended.Diff(existing)
ds := dc.collect()
if assert.Len(ds.Gone.Snapshot(), 1, "Should have one deleted item.") {
it, _ := ds.Gone.Any(func(*Deployment) bool { return true })
assert.Equal(string(it.SourceID.Location.Repo), repoOne)
}
if assert.Len(ds.Same.Snapshot(), 1, "Should have one unchanged item.") {
it, _ := ds.Same.Any(func(*Deployment) bool { return true })
assert.Equal(string(it.SourceID.Location.Repo), repoTwo)
}
if assert.Len(ds.Changed, 1, "Should have one modified item.") {
assert.Equal(repoThree, string(ds.Changed[0].name.ManifestID.Source.Repo))
assert.Equal(repoThree, string(ds.Changed[0].Prior.SourceID.Location.Repo))
assert.Equal(repoThree, string(ds.Changed[0].Post.SourceID.Location.Repo))
assert.Equal(ds.Changed[0].Post.NumInstances, 1)
assert.Equal(ds.Changed[0].Prior.NumInstances, 2)
}
if assert.Equal(ds.New.Len(), 1, "Should have one added item.") {
it, _ := ds.New.Any(func(*Deployment) bool { return true })
assert.Equal(string(it.SourceID.Location.Repo), repoFour)
}
}
示例8: TestBuildDeployment
func TestBuildDeployment(t *testing.T) {
assert := assert.New(t)
m := &Manifest{
Source: SourceLocation{},
Owners: []string{"[email protected]"},
Kind: ManifestKindService,
}
sp := DeploySpec{
DeployConfig: DeployConfig{
Resources: Resources{},
Args: []string{},
Env: Env{},
NumInstances: 3,
Volumes: Volumes{
&Volume{"h", "c", "RO"},
},
},
Version: semv.MustParse("1.2.3"),
clusterName: "cluster.name",
}
var ih []DeploySpec
nick := "cn"
state := &State{Defs: Defs{Clusters: Clusters{nick: &Cluster{BaseURL: "http://not"}}}}
d, err := BuildDeployment(state, m, nick, sp, ih)
if assert.NoError(err) {
if assert.Len(d.DeployConfig.Volumes, 1) {
assert.Equal("c", d.DeployConfig.Volumes[0].Container)
}
assert.Equal(nick, d.ClusterName)
}
}
示例9: TestInvokeHarvest
func TestInvokeHarvest(t *testing.T) {
assert := assert.New(t)
exe := justCommand(t, []string{`sous`, `harvest`, `sms-continual-test`})
assert.NotNil(exe)
assert.Len(exe.Args, 1)
}
示例10: TestInvokeConfig
/*
usage: sous config Invoking sous config with no arguments lists all configuration key/value pairs.
If you pass just a single argument (a key) sous config will output just the
value of that key. You can set a key by providing both a key and a value.
usage: sous config [<key> [value]]
*/
func TestInvokeConfig(t *testing.T) {
assert := assert.New(t)
exe := justCommand(t, []string{`sous`, `config`})
assert.NotNil(exe)
assert.Len(exe.Args, 0)
exe = justCommand(t, []string{`sous`, `config`, `x`})
assert.NotNil(exe)
assert.Len(exe.Args, 1)
exe = justCommand(t, []string{`sous`, `config`, `x`, `7`})
assert.NotNil(exe)
assert.Len(exe.Args, 2)
}
示例11: TestInvokeUpdate
func TestInvokeUpdate(t *testing.T) {
assert := assert.New(t)
exe := justCommand(t, []string{`sous`, `update`})
assert.NotNil(exe)
assert.Len(exe.Args, 0)
}
示例12: TestProductionReady
func TestProductionReady(t *testing.T) {
assert := assert.New(t)
bc := BuildConfig{
Strict: true,
Tag: "1.2.3",
Repo: "github.com/opentable/present",
Revision: "abcdef",
Context: &BuildContext{
Sh: &shell.Sh{},
Source: SourceContext{
RemoteURL: "github.com/opentable/present",
RemoteURLs: []string{
"github.com/opentable/present",
"github.com/opentable/also",
},
Revision: "abcdef",
NearestTagName: "1.2.3",
NearestTagRevision: "abcdef",
Tags: []Tag{
Tag{Name: "1.2.3"},
},
},
},
}
ctx := bc.NewContext()
assert.Len(ctx.Advisories, 0)
assert.NoError(bc.GuardStrict(ctx))
}
示例13: TestInvokeContext
/*
usage: sous context
context prints out sous's view of your current context
*/
func TestInvokeContext(t *testing.T) {
assert := assert.New(t)
exe := justCommand(t, []string{`sous`, `context`})
assert.NotNil(exe)
assert.Len(exe.Args, 0)
}
示例14: TestInvokeRectifyDryruns
func TestInvokeRectifyDryruns(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
testDryRun := func(which string) (sous.Deployer, sous.Registry) {
exe := justCommand(t, []string{`sous`, `rectify`, `-dry-run`, which, `-repo`, `github.com/somewhere`})
assert.Len(exe.Args, 0)
require.IsType(&SousRectify{}, exe.Cmd)
rect := exe.Cmd.(*SousRectify)
// currently no easy way to tell if the deploy client is live or dummy
return nil, rect.Resolver.Registry
}
_, r := testDryRun("both")
assert.IsType(&sous.DummyRegistry{}, r)
_, r = testDryRun("none")
assert.IsType(&docker.NameCache{}, r)
_, r = testDryRun("scheduler")
assert.IsType(&docker.NameCache{}, r)
_, r = testDryRun("registry")
assert.IsType(&sous.DummyRegistry{}, r)
}
示例15: TestValidateRepair
func TestValidateRepair(t *testing.T) {
dc := DeployConfig{
Volumes: Volumes{nil, &Volume{}},
Resources: make(Resources),
}
dc.Resources["cpus"] = "0.25"
dc.Resources["memory"] = "356"
dc.Resources["ports"] = "2"
assert.Len(t, dc.Volumes, 2)
flaws := dc.Validate()
assert.Len(t, flaws, 1)
fs, es := RepairAll(flaws)
assert.Len(t, fs, 0)
assert.Len(t, es, 0)
assert.Len(t, dc.Volumes, 1)
}