本文整理汇总了Golang中github.com/wallyworld/core/version.MustParse函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParse函数的具体用法?Golang MustParse怎么用?Golang MustParse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustParse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestPerformUpgrade
func (s *upgradeSuite) TestPerformUpgrade(c *gc.C) {
s.PatchValue(upgrades.UpgradeOperations, upgradeOperations)
for i, test := range upgradeTests {
c.Logf("%d: %s", i, test.about)
var messages []string
ctx := &mockContext{
messages: messages,
}
fromVersion := version.Zero
if test.fromVersion != "" {
fromVersion = version.MustParse(test.fromVersion)
}
toVersion := version.MustParse("1.18.0")
if test.toVersion != "" {
toVersion = version.MustParse(test.toVersion)
}
vers := version.Current
vers.Number = toVersion
s.PatchValue(&version.Current, vers)
err := upgrades.PerformUpgrade(fromVersion, test.target, ctx)
if test.err == "" {
c.Check(err, gc.IsNil)
} else {
c.Check(err, gc.ErrorMatches, test.err)
}
c.Check(ctx.messages, jc.DeepEquals, test.expectedSteps)
}
}
示例2: TestReadConfReadsLegacyFormatAndWritesNew
func (*format_1_16Suite) TestReadConfReadsLegacyFormatAndWritesNew(c *gc.C) {
dataDir := c.MkDir()
formatPath := filepath.Join(dataDir, legacyFormatFilename)
err := utils.AtomicWriteFile(formatPath, []byte(legacyFormatFileContents), 0600)
c.Assert(err, gc.IsNil)
configPath := filepath.Join(dataDir, agentConfigFilename)
err = utils.AtomicWriteFile(configPath, []byte(agentConfig1_16Contents), 0600)
c.Assert(err, gc.IsNil)
config, err := ReadConfig(configPath)
c.Assert(err, gc.IsNil)
c.Assert(config, gc.NotNil)
// Test we wrote a currently valid config.
config, err = ReadConfig(configPath)
c.Assert(err, gc.IsNil)
c.Assert(config, gc.NotNil)
c.Assert(config.UpgradedToVersion(), jc.DeepEquals, version.MustParse("1.16.0"))
c.Assert(config.Jobs(), gc.HasLen, 0)
// Old format was deleted.
assertFileNotExist(c, formatPath)
// And new contents were written.
data, err := ioutil.ReadFile(configPath)
c.Assert(err, gc.IsNil)
c.Assert(string(data), gc.Not(gc.Equals), agentConfig1_16Contents)
}
示例3: TestAllowedTargetVersionSuite
func (s *AllowedTargetVersionSuite) TestAllowedTargetVersionSuite(c *gc.C) {
cases := []allowedTest{
{current: "1.2.3", target: "1.3.3", allowed: true},
{current: "1.2.3", target: "1.2.3", allowed: true},
{current: "1.2.3", target: "2.2.3", allowed: true},
{current: "1.2.3", target: "1.1.3", allowed: false},
{current: "1.2.3", target: "1.2.2", allowed: true},
{current: "1.2.3", target: "0.2.3", allowed: false},
}
for i, test := range cases {
c.Logf("test case %d, %#v", i, test)
current := version.MustParse(test.current)
target := version.MustParse(test.target)
c.Check(upgrader.AllowedTargetVersion(current, target), gc.Equals, test.allowed)
}
}
示例4: binary
// binary returns the tools metadata's binary version,
// which may be used for map lookup.
func (t *ToolsMetadata) binary() version.Binary {
return version.Binary{
Number: version.MustParse(t.Version),
Series: t.Release,
Arch: t.Arch,
}
}
示例5: checkCanUpgrade
func (st *State) checkCanUpgrade(currentVersion, newVersion string) error {
matchCurrent := "^" + regexp.QuoteMeta(currentVersion) + "-"
matchNew := "^" + regexp.QuoteMeta(newVersion) + "-"
// Get all machines and units with a different or empty version.
sel := bson.D{{"$or", []bson.D{
{{"tools", bson.D{{"$exists", false}}}},
{{"$and", []bson.D{
{{"tools.version", bson.D{{"$not", bson.RegEx{matchCurrent, ""}}}}},
{{"tools.version", bson.D{{"$not", bson.RegEx{matchNew, ""}}}}},
}}},
}}}
var agentTags []string
for _, collection := range []*mgo.Collection{st.machines, st.units} {
var doc struct {
Id string `bson:"_id"`
}
iter := collection.Find(sel).Select(bson.D{{"_id", 1}}).Iter()
for iter.Next(&doc) {
switch collection.Name {
case "machines":
agentTags = append(agentTags, names.MachineTag(doc.Id))
case "units":
agentTags = append(agentTags, names.UnitTag(doc.Id))
}
}
if err := iter.Err(); err != nil {
return err
}
}
if len(agentTags) > 0 {
return newVersionInconsistentError(version.MustParse(currentVersion), agentTags)
}
return nil
}
示例6: TestId
func (s *productSpecSuite) TestId(c *gc.C) {
toolsConstraint := tools.NewVersionedToolsConstraint(version.MustParse("1.13.0"), simplestreams.LookupParams{
Series: []string{"precise"},
Arches: []string{"amd64"},
})
ids, err := toolsConstraint.Ids()
c.Assert(err, gc.IsNil)
c.Assert(ids, gc.DeepEquals, []string{"com.ubuntu.juju:12.04:amd64"})
}
示例7: TestSetUpgradedToVersion
func (*suite) TestSetUpgradedToVersion(c *gc.C) {
conf, err := agent.NewAgentConfig(attributeParams)
c.Assert(err, gc.IsNil)
c.Assert(conf.UpgradedToVersion(), gc.Equals, version.Current.Number)
expectVers := version.MustParse("3.4.5")
conf.SetUpgradedToVersion(expectVers)
c.Assert(conf.UpgradedToVersion(), gc.Equals, expectVers)
}
示例8: TestReadConfWithExisting1_18ConfigFileContents
func (*format_1_18Suite) TestReadConfWithExisting1_18ConfigFileContents(c *gc.C) {
dataDir := c.MkDir()
configPath := filepath.Join(dataDir, agentConfigFilename)
err := utils.AtomicWriteFile(configPath, []byte(agentConfig1_18Contents), 0600)
c.Assert(err, gc.IsNil)
config, err := ReadConfig(configPath)
c.Assert(err, gc.IsNil)
c.Assert(config.UpgradedToVersion(), jc.DeepEquals, version.MustParse("1.17.5.1"))
c.Assert(config.Jobs(), jc.DeepEquals, []params.MachineJob{params.JobManageEnviron})
}
示例9: TestMissingAttributes
func (s *format_1_18Suite) TestMissingAttributes(c *gc.C) {
dataDir := c.MkDir()
configPath := filepath.Join(dataDir, agentConfigFilename)
err := utils.AtomicWriteFile(configPath, []byte(configData1_18WithoutUpgradedToVersion), 0600)
c.Assert(err, gc.IsNil)
readConfig, err := ReadConfig(configPath)
c.Assert(err, gc.IsNil)
c.Assert(readConfig.UpgradedToVersion(), gc.Equals, version.MustParse("1.16.0"))
c.Assert(readConfig.LogDir(), gc.Equals, "/var/log/juju")
c.Assert(readConfig.DataDir(), gc.Equals, "/var/lib/juju")
}
示例10: ValidateToolsMetadata
// ValidateToolsMetadata attempts to load tools metadata for the specified cloud attributes and returns
// any tools versions found, or an error if the metadata could not be loaded.
func ValidateToolsMetadata(params *ToolsMetadataLookupParams) ([]string, *simplestreams.ResolveInfo, error) {
if len(params.Architectures) == 0 {
return nil, nil, fmt.Errorf("required parameter arches not specified")
}
if len(params.Sources) == 0 {
return nil, nil, fmt.Errorf("required parameter sources not specified")
}
if params.Version == "" && params.Major == 0 {
params.Version = version.Current.Number.String()
}
var toolsConstraint *ToolsConstraint
if params.Version == "" {
toolsConstraint = NewGeneralToolsConstraint(params.Major, params.Minor, false, simplestreams.LookupParams{
CloudSpec: simplestreams.CloudSpec{
Region: params.Region,
Endpoint: params.Endpoint,
},
Series: []string{params.Series},
Arches: params.Architectures,
})
} else {
versNum, err := version.Parse(params.Version)
if err != nil {
return nil, nil, err
}
toolsConstraint = NewVersionedToolsConstraint(versNum, simplestreams.LookupParams{
CloudSpec: simplestreams.CloudSpec{
Region: params.Region,
Endpoint: params.Endpoint,
},
Series: []string{params.Series},
Arches: params.Architectures,
})
}
matchingTools, resolveInfo, err := Fetch(params.Sources, simplestreams.DefaultIndexPath, toolsConstraint, false)
if err != nil {
return nil, resolveInfo, err
}
if len(matchingTools) == 0 {
return nil, resolveInfo, fmt.Errorf("no matching tools found for constraint %+v", toolsConstraint)
}
versions := make([]string, len(matchingTools))
for i, tm := range matchingTools {
vers := version.Binary{
Number: version.MustParse(tm.Version),
Series: tm.Release,
Arch: tm.Arch,
}
versions[i] = vers.String()
}
return versions, resolveInfo, nil
}
示例11: TestWatchAPIVersion
func (s *machineUpgraderSuite) TestWatchAPIVersion(c *gc.C) {
w, err := s.st.WatchAPIVersion(s.rawMachine.Tag())
c.Assert(err, gc.IsNil)
defer statetesting.AssertStop(c, w)
wc := statetesting.NewNotifyWatcherC(c, s.BackingState, w)
// Initial event
wc.AssertOneChange()
vers := version.MustParse("10.20.34")
err = statetesting.SetAgentVersion(s.BackingState, vers)
c.Assert(err, gc.IsNil)
// One change noticing the new version
wc.AssertOneChange()
// Setting the version to the same value doesn't trigger a change
err = statetesting.SetAgentVersion(s.BackingState, vers)
c.Assert(err, gc.IsNil)
wc.AssertNoChange()
vers = version.MustParse("10.20.35")
err = statetesting.SetAgentVersion(s.BackingState, vers)
c.Assert(err, gc.IsNil)
wc.AssertOneChange()
statetesting.AssertStop(c, w)
wc.AssertClosed()
}
示例12: TestInvalidLocalSource
func (s *BootstrapSuite) TestInvalidLocalSource(c *gc.C) {
s.PatchValue(&version.Current.Number, version.MustParse("1.2.0"))
env, fake := makeEmptyFakeHome(c)
defer fake.Restore()
// Bootstrap the environment with an invalid source.
// The command returns with an error.
ctx := coretesting.Context(c)
code := cmd.Main(&BootstrapCommand{}, ctx, []string{"--metadata-source", c.MkDir()})
c.Check(code, gc.Equals, 1)
// Now check that there are no tools available.
_, err := envtools.FindTools(
env, version.Current.Major, version.Current.Minor, coretools.Filter{}, envtools.DoNotAllowRetry)
c.Assert(err, gc.FitsTypeOf, errors.NotFoundf(""))
}
示例13: TestAutoSyncLocalSource
func (s *BootstrapSuite) TestAutoSyncLocalSource(c *gc.C) {
sourceDir := createToolsSource(c, vAll)
s.PatchValue(&version.Current.Number, version.MustParse("1.2.0"))
env, fake := makeEmptyFakeHome(c)
defer fake.Restore()
// Bootstrap the environment with the valid source.
// The bootstrapping has to show no error, because the tools
// are automatically synchronized.
ctx := coretesting.Context(c)
code := cmd.Main(&BootstrapCommand{}, ctx, []string{"--metadata-source", sourceDir})
c.Check(code, gc.Equals, 0)
// Now check the available tools which are the 1.2.0 envtools.
checkTools(c, env, v120All)
}
示例14: TestMissingAttributes
func (s *format_1_16Suite) TestMissingAttributes(c *gc.C) {
dataDir := c.MkDir()
formatPath := filepath.Join(dataDir, legacyFormatFilename)
err := utils.AtomicWriteFile(formatPath, []byte(legacyFormatFileContents), 0600)
c.Assert(err, gc.IsNil)
configPath := filepath.Join(dataDir, agentConfigFilename)
err = utils.AtomicWriteFile(configPath, []byte(configDataWithoutNewAttributes), 0600)
c.Assert(err, gc.IsNil)
readConfig, err := ReadConfig(configPath)
c.Assert(err, gc.IsNil)
c.Assert(readConfig.UpgradedToVersion(), gc.Equals, version.MustParse("1.16.0"))
c.Assert(readConfig.LogDir(), gc.Equals, "/var/log/juju")
c.Assert(readConfig.DataDir(), gc.Equals, "/var/lib/juju")
// Test data doesn't include a StateServerKey so StateServingInfo
// should *not* be available
_, available := readConfig.StateServingInfo()
c.Assert(available, gc.Equals, false)
}
示例15: TestNumberMarshalUnmarshal
func (*suite) TestNumberMarshalUnmarshal(c *gc.C) {
for _, m := range marshallers {
c.Logf("encoding %v", m.name)
type doc struct {
Version *version.Number
}
// Work around goyaml bug #1096149
// SetYAML is not called for non-pointer fields.
np := version.MustParse("1.2.3")
v := doc{&np}
data, err := m.marshal(&v)
c.Assert(err, gc.IsNil)
var nv doc
err = m.unmarshal(data, &nv)
c.Assert(err, gc.IsNil)
c.Assert(nv, gc.DeepEquals, v)
}
}