本文整理汇总了Golang中github.com/juju/version.MustParse函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParse函数的具体用法?Golang MustParse怎么用?Golang MustParse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustParse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestPerformUpgrade
func (s *upgradeSuite) TestPerformUpgrade(c *gc.C) {
s.PatchValue(upgrades.StateUpgradeOperations, stateUpgradeOperations)
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)
}
s.PatchValue(&jujuversion.Current, toVersion)
err := upgrades.PerformUpgrade(fromVersion, test.targets, ctx)
if test.err == "" {
c.Check(err, jc.ErrorIsNil)
} else {
c.Check(err, gc.ErrorMatches, test.err)
}
c.Check(ctx.messages, jc.DeepEquals, test.expectedSteps)
}
}
示例2: TestFindToolsExactNotInStorage
func (s *toolsSuite) TestFindToolsExactNotInStorage(c *gc.C) {
mockToolsStorage := &mockToolsStorage{}
s.PatchValue(&jujuversion.Current, version.MustParse("1.22-beta1"))
s.testFindToolsExact(c, mockToolsStorage, false, true)
s.PatchValue(&jujuversion.Current, version.MustParse("1.22.0"))
s.testFindToolsExact(c, mockToolsStorage, false, false)
}
示例3: TestModelInfo
func (s *ClientSuite) TestModelInfo(c *gc.C) {
var stub jujutesting.Stub
owner := names.NewUserTag("owner")
apiCaller := apitesting.APICallerFunc(func(objType string, v int, id, request string, arg, result interface{}) error {
stub.AddCall(objType+"."+request, id, arg)
*(result.(*params.MigrationModelInfo)) = params.MigrationModelInfo{
UUID: "uuid",
Name: "name",
OwnerTag: owner.String(),
AgentVersion: version.MustParse("1.2.3"),
}
return nil
})
client := migrationmaster.NewClient(apiCaller, nil)
model, err := client.ModelInfo()
stub.CheckCalls(c, []jujutesting.StubCall{
{"MigrationMaster.ModelInfo", []interface{}{"", nil}},
})
c.Check(err, jc.ErrorIsNil)
c.Check(model, jc.DeepEquals, migration.ModelInfo{
UUID: "uuid",
Name: "name",
Owner: owner,
AgentVersion: version.MustParse("1.2.3"),
})
}
示例4: TestAbortCurrentUpgrade
func (s *serverSuite) TestAbortCurrentUpgrade(c *gc.C) {
// Create a provisioned controller.
machine, err := s.State.AddMachine("series", state.JobManageModel)
c.Assert(err, jc.ErrorIsNil)
err = machine.SetProvisioned(instance.Id("i-blah"), "fake-nonce", nil)
c.Assert(err, jc.ErrorIsNil)
// Start an upgrade.
_, err = s.State.EnsureUpgradeInfo(
machine.Id(),
version.MustParse("1.2.3"),
version.MustParse("9.8.7"),
)
c.Assert(err, jc.ErrorIsNil)
isUpgrading, err := s.State.IsUpgrading()
c.Assert(err, jc.ErrorIsNil)
c.Assert(isUpgrading, jc.IsTrue)
// Abort it.
err = s.client.AbortCurrentUpgrade()
c.Assert(err, jc.ErrorIsNil)
isUpgrading, err = s.State.IsUpgrading()
c.Assert(err, jc.ErrorIsNil)
c.Assert(isUpgrading, jc.IsFalse)
}
示例5: TestBootstrapGUISuccessRemote
func (s *bootstrapSuite) TestBootstrapGUISuccessRemote(c *gc.C) {
s.PatchValue(bootstrap.GUIFetchMetadata, func(stream string, sources ...simplestreams.DataSource) ([]*gui.Metadata, error) {
c.Assert(stream, gc.Equals, gui.ReleasedStream)
c.Assert(sources[0].Description(), gc.Equals, "gui simplestreams")
c.Assert(sources[0].RequireSigned(), jc.IsTrue)
return []*gui.Metadata{{
Version: version.MustParse("2.0.42"),
FullPath: "https://1.2.3.4/juju-gui-2.0.42.tar.bz2",
SHA256: "hash-2.0.42",
Size: 42,
}, {
Version: version.MustParse("2.0.47"),
FullPath: "https://1.2.3.4/juju-gui-2.0.47.tar.bz2",
SHA256: "hash-2.0.47",
Size: 47,
}}, nil
})
env := newEnviron("foo", useDefaultKeys, nil)
ctx := coretesting.Context(c)
err := bootstrap.Bootstrap(modelcmd.BootstrapContext(ctx), env, bootstrap.BootstrapParams{
GUIDataSourceBaseURL: "https://1.2.3.4/gui/sources",
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(coretesting.Stderr(ctx), jc.Contains, "Preparing for Juju GUI 2.0.42 release installation\n")
// The most recent GUI release info has been stored.
c.Assert(env.instanceConfig.GUI.URL, gc.Equals, "https://1.2.3.4/juju-gui-2.0.42.tar.bz2")
c.Assert(env.instanceConfig.GUI.Version.String(), gc.Equals, "2.0.42")
c.Assert(env.instanceConfig.GUI.Size, gc.Equals, int64(42))
c.Assert(env.instanceConfig.GUI.SHA256, gc.Equals, "hash-2.0.42")
}
示例6: TestGUIArchives
func (s *clientSuite) TestGUIArchives(c *gc.C) {
client := s.APIState.Client()
called := false
response := params.GUIArchiveResponse{
Versions: []params.GUIArchiveVersion{{
Version: version.MustParse("1.0.0"),
SHA256: "hash1",
Current: false,
}, {
Version: version.MustParse("2.0.0"),
SHA256: "hash2",
Current: true,
}},
}
// Set up a fake endpoint for tests.
defer fakeAPIEndpoint(c, client, "/gui-archive", "GET",
func(w http.ResponseWriter, req *http.Request) {
defer req.Body.Close()
called = true
sendJSONResponse(c, w, response)
},
).Close()
versions, err := client.GUIArchives()
c.Assert(err, jc.ErrorIsNil)
c.Assert(versions, jc.DeepEquals, response.Versions)
c.Assert(called, jc.IsTrue)
}
示例7: TestHighVersion
func (*interfaceSuite) TestHighVersion(c *gc.C) {
read, err := readInterfaces(version.MustParse("2.1.9"), parseJSON(c, interfacesResponse))
c.Assert(err, jc.ErrorIsNil)
c.Assert(read, gc.HasLen, 1)
_, err = readInterface(version.MustParse("2.1.9"), parseJSON(c, interfaceResponse))
c.Assert(err, jc.ErrorIsNil)
}
示例8: TestWatchAPIVersion
func (s *machineUpgraderSuite) TestWatchAPIVersion(c *gc.C) {
w, err := s.st.WatchAPIVersion(s.rawMachine.Tag().String())
c.Assert(err, jc.ErrorIsNil)
wc := watchertest.NewNotifyWatcherC(c, w, s.BackingState.StartSync)
defer wc.AssertStops()
// Initial event
wc.AssertOneChange()
// One change noticing the new version
vers := version.MustParse("10.20.34")
err = statetesting.SetAgentVersion(s.BackingState, vers)
c.Assert(err, jc.ErrorIsNil)
wc.AssertOneChange()
// Setting the version to the same value doesn't trigger a change
err = statetesting.SetAgentVersion(s.BackingState, vers)
c.Assert(err, jc.ErrorIsNil)
wc.AssertNoChange()
// Another change noticing another new version
vers = version.MustParse("10.20.35")
err = statetesting.SetAgentVersion(s.BackingState, vers)
c.Assert(err, jc.ErrorIsNil)
wc.AssertOneChange()
}
示例9: stateUpgradeOperations
func stateUpgradeOperations() []upgrades.Operation {
steps := []upgrades.Operation{
&mockUpgradeOperation{
targetVersion: version.MustParse("1.11.0"),
steps: []upgrades.Step{
newUpgradeStep("state step 1 - 1.11.0", upgrades.Controller),
newUpgradeStep("state step 2 error", upgrades.Controller),
newUpgradeStep("state step 3 - 1.11.0", upgrades.Controller),
},
},
&mockUpgradeOperation{
targetVersion: version.MustParse("1.21.0"),
steps: []upgrades.Step{
newUpgradeStep("state step 1 - 1.21.0", upgrades.DatabaseMaster),
newUpgradeStep("state step 2 - 1.21.0", upgrades.Controller),
},
},
&mockUpgradeOperation{
targetVersion: version.MustParse("1.22.0"),
steps: []upgrades.Step{
newUpgradeStep("state step 1 - 1.22.0", upgrades.DatabaseMaster),
newUpgradeStep("state step 2 - 1.22.0", upgrades.Controller),
},
},
}
return steps
}
示例10: TestLowVersion
func (*interfaceSuite) TestLowVersion(c *gc.C) {
_, err := readInterfaces(version.MustParse("1.9.0"), parseJSON(c, interfacesResponse))
c.Assert(err, jc.Satisfies, IsUnsupportedVersionError)
c.Assert(err.Error(), gc.Equals, `no interface read func for version 1.9.0`)
_, err = readInterface(version.MustParse("1.9.0"), parseJSON(c, interfaceResponse))
c.Assert(err, jc.Satisfies, IsUnsupportedVersionError)
c.Assert(err.Error(), gc.Equals, `no interface read func for version 1.9.0`)
}
示例11: TestBlockUpgradeJujuWithRealUpload
func (s *UpgradeJujuSuite) TestBlockUpgradeJujuWithRealUpload(c *gc.C) {
s.Reset(c)
s.PatchValue(&jujuversion.Current, version.MustParse("1.99.99"))
cmd := newUpgradeJujuCommand(map[int]version.Number{2: version.MustParse("1.99.99")})
// Block operation
s.BlockAllChanges(c, "TestBlockUpgradeJujuWithRealUpload")
_, err := coretesting.RunCommand(c, cmd, "--build-agent")
coretesting.AssertOperationWasBlocked(c, err, ".*TestBlockUpgradeJujuWithRealUpload.*")
}
示例12: TestPreferredStream
func (s *SimpleStreamsToolsSuite) TestPreferredStream(c *gc.C) {
for i, test := range preferredStreamTests {
c.Logf("\ntest %d", i)
s.PatchValue(&jujuversion.Current, version.MustParse(test.currentVers))
var vers *version.Number
if test.explicitVers != "" {
v := version.MustParse(test.explicitVers)
vers = &v
}
obtained := envtools.PreferredStream(vers, test.forceDevel, test.streamInConfig)
c.Check(obtained, gc.Equals, test.expected)
}
}
示例13: TestUpgradeJujuWithRealUpload
func (s *UpgradeJujuSuite) TestUpgradeJujuWithRealUpload(c *gc.C) {
s.Reset(c)
s.PatchValue(&jujuversion.Current, version.MustParse("1.99.99"))
cmd := newUpgradeJujuCommand(map[int]version.Number{2: version.MustParse("1.99.99")})
_, err := coretesting.RunCommand(c, cmd, "--build-agent")
c.Assert(err, jc.ErrorIsNil)
vers := version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: series.HostSeries(),
}
vers.Build = 1
s.checkToolsUploaded(c, vers, vers.Number)
}
示例14: TestClientAgentVersion
func (s *clientSuite) TestClientAgentVersion(c *gc.C) {
current := version.MustParse("1.2.0")
s.PatchValue(&jujuversion.Current, current)
result, err := s.APIState.Client().AgentVersion()
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.Equals, current)
}
示例15: TestFindAvailableToolsSpecificVersion
func (s *toolsSuite) TestFindAvailableToolsSpecificVersion(c *gc.C) {
currentVersion := version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: series.HostSeries(),
}
currentVersion.Major = 2
currentVersion.Minor = 3
s.PatchValue(&jujuversion.Current, currentVersion.Number)
var findToolsCalled int
s.PatchValue(bootstrap.FindTools, func(_ environs.Environ, major, minor int, stream string, f tools.Filter) (tools.List, error) {
c.Assert(f.Number.Major, gc.Equals, 10)
c.Assert(f.Number.Minor, gc.Equals, 11)
c.Assert(f.Number.Patch, gc.Equals, 12)
c.Assert(stream, gc.Equals, "released")
findToolsCalled++
return []*tools.Tools{
&tools.Tools{
Version: currentVersion,
URL: "http://testing.invalid/tools.tar.gz",
},
}, nil
})
env := newEnviron("foo", useDefaultKeys, nil)
toolsVersion := version.MustParse("10.11.12")
result, err := bootstrap.FindAvailableTools(env, &toolsVersion, nil, nil, false)
c.Assert(err, jc.ErrorIsNil)
c.Assert(findToolsCalled, gc.Equals, 1)
c.Assert(result, jc.DeepEquals, tools.List{
&tools.Tools{
Version: currentVersion,
URL: "http://testing.invalid/tools.tar.gz",
},
})
}