本文整理匯總了Golang中github.com/juju/utils/set.Strings.Size方法的典型用法代碼示例。如果您正苦於以下問題:Golang Strings.Size方法的具體用法?Golang Strings.Size怎麽用?Golang Strings.Size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/utils/set.Strings
的用法示例。
在下文中一共展示了Strings.Size方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: commonServiceInstances
// commonServiceInstances returns instances with
// services in common with the specified machine.
func commonServiceInstances(st *state.State, m *state.Machine) ([]instance.Id, error) {
units, err := m.Units()
if err != nil {
return nil, err
}
var instanceIdSet set.Strings
for _, unit := range units {
if !unit.IsPrincipal() {
continue
}
instanceIds, err := state.ServiceInstances(st, unit.ServiceName())
if err != nil {
return nil, err
}
for _, instanceId := range instanceIds {
instanceIdSet.Add(string(instanceId))
}
}
instanceIds := make([]instance.Id, instanceIdSet.Size())
// Sort values to simplify testing.
for i, instanceId := range instanceIdSet.SortedValues() {
instanceIds[i] = instance.Id(instanceId)
}
return instanceIds, nil
}
示例2: TestUninitialized
func (stringSetSuite) TestUninitialized(c *gc.C) {
var uninitialized set.Strings
c.Assert(uninitialized.Size(), gc.Equals, 0)
c.Assert(uninitialized.IsEmpty(), gc.Equals, true)
// You can get values and sorted values from an unitialized set.
AssertValues(c, uninitialized)
// All contains checks are false
c.Assert(uninitialized.Contains("foo"), gc.Equals, false)
// Remove works on an uninitialized Strings
uninitialized.Remove("foo")
var other set.Strings
// Union returns a new set that is empty but initialized.
c.Assert(uninitialized.Union(other), gc.DeepEquals, set.NewStrings())
c.Assert(uninitialized.Intersection(other), gc.DeepEquals, set.NewStrings())
c.Assert(uninitialized.Difference(other), gc.DeepEquals, set.NewStrings())
other = set.NewStrings("foo", "bar")
c.Assert(uninitialized.Union(other), gc.DeepEquals, other)
c.Assert(uninitialized.Intersection(other), gc.DeepEquals, set.NewStrings())
c.Assert(uninitialized.Difference(other), gc.DeepEquals, set.NewStrings())
c.Assert(other.Union(uninitialized), gc.DeepEquals, other)
c.Assert(other.Intersection(uninitialized), gc.DeepEquals, set.NewStrings())
c.Assert(other.Difference(uninitialized), gc.DeepEquals, other)
// Once something is added, the set becomes initialized.
uninitialized.Add("foo")
AssertValues(c, uninitialized, "foo")
}
示例3: testToolsMetadata
func (s *BootstrapSuite) testToolsMetadata(c *gc.C, exploded bool) {
provider, err := environs.Provider(s.envcfg.Type())
c.Assert(err, gc.IsNil)
env, err := provider.Open(s.envcfg)
c.Assert(err, gc.IsNil)
oldMetadata, err := envtools.ReadMetadata(env.Storage())
c.Assert(err, gc.IsNil)
_, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId))
c.Assert(err, gc.IsNil)
err = cmd.Run(nil)
c.Assert(err, gc.IsNil)
newMetadata, err := envtools.ReadMetadata(env.Storage())
c.Assert(err, gc.IsNil)
if !exploded {
c.Assert(newMetadata, gc.HasLen, len(oldMetadata))
} else {
// new metadata should have more tools.
c.Assert(len(newMetadata), jc.GreaterThan, len(oldMetadata))
var expectedSeries set.Strings
for _, series := range version.SupportedSeries() {
os, err := version.GetOSFromSeries(series)
c.Assert(err, gc.IsNil)
if os == version.Ubuntu {
expectedSeries.Add(series)
}
}
c.Assert(newMetadata, gc.HasLen, expectedSeries.Size())
for _, m := range newMetadata {
c.Assert(expectedSeries.Contains(m.Release), jc.IsTrue)
}
}
}
示例4: testToolsMetadata
func (s *BootstrapSuite) testToolsMetadata(c *gc.C, exploded bool) {
provider, err := environs.Provider(s.envcfg.Type())
c.Assert(err, gc.IsNil)
env, err := provider.Open(s.envcfg)
c.Assert(err, gc.IsNil)
envtesting.RemoveFakeToolsMetadata(c, env.Storage())
_, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId))
c.Assert(err, gc.IsNil)
err = cmd.Run(nil)
c.Assert(err, gc.IsNil)
// We don't write metadata at bootstrap anymore.
simplestreamsMetadata, err := envtools.ReadMetadata(env.Storage())
c.Assert(err, gc.IsNil)
c.Assert(simplestreamsMetadata, gc.HasLen, 0)
// The tools should have been added to state, and
// exploded into each of the supported series of
// the same operating system if the tools were uploaded.
st, err := state.Open(&mongo.MongoInfo{
Info: mongo.Info{
Addrs: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
},
Password: testPasswordHash(),
}, mongo.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
defer st.Close()
var expectedSeries set.Strings
if exploded {
for _, series := range version.SupportedSeries() {
os, err := version.GetOSFromSeries(series)
c.Assert(err, gc.IsNil)
if os == version.Current.OS {
expectedSeries.Add(series)
}
}
} else {
expectedSeries.Add(version.Current.Series)
}
storage, err := st.ToolsStorage()
c.Assert(err, gc.IsNil)
defer storage.Close()
metadata, err := storage.AllMetadata()
c.Assert(err, gc.IsNil)
c.Assert(metadata, gc.HasLen, expectedSeries.Size())
for _, m := range metadata {
c.Assert(expectedSeries.Contains(m.Version.Series), jc.IsTrue)
}
}
示例5: AssertValues
// Helper methods for the tests.
func AssertValues(c *gc.C, s set.Strings, expected ...string) {
values := s.Values()
// Expect an empty slice, not a nil slice for values.
if expected == nil {
expected = []string{}
}
sort.Strings(expected)
sort.Strings(values)
c.Assert(values, gc.DeepEquals, expected)
c.Assert(s.Size(), gc.Equals, len(expected))
// Check the sorted values too.
sorted := s.SortedValues()
c.Assert(sorted, gc.DeepEquals, expected)
}