本文整理汇总了Golang中launchpad/net/juju-core/version.MustParse函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParse函数的具体用法?Golang MustParse怎么用?Golang MustParse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustParse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUpgradeJuju
func (s *UpgradeJujuSuite) TestUpgradeJuju(c *C) {
oldVersion := version.Current
putTools = testPutTools
defer func() {
version.Current = oldVersion
putTools = environs.PutTools
}()
for i, test := range upgradeJujuTests {
c.Logf("%d. %s", i, test.about)
// Set up the test preconditions.
s.Reset(c)
for _, v := range test.private {
upload(s.Conn.Environ.Storage(), v)
}
for _, v := range test.public {
storage := s.Conn.Environ.PublicStorage().(environs.Storage)
upload(storage, v)
}
version.Current = version.MustParseBinary(test.currentVersion)
err := SetAgentVersion(s.State, version.MustParse(test.agentVersion), false)
c.Assert(err, IsNil)
// Run the command
com := &UpgradeJujuCommand{}
err = com.Init(newFlagSet(), test.args)
if test.expectInitErr != "" {
c.Check(err, ErrorMatches, test.expectInitErr)
continue
}
err = com.Run(&cmd.Context{c.MkDir(), nil, ioutil.Discard, ioutil.Discard})
if test.expectErr != "" {
c.Check(err, ErrorMatches, test.expectErr)
continue
}
c.Assert(err, IsNil)
cfg, err := s.State.EnvironConfig()
c.Check(err, IsNil)
c.Check(cfg.AgentVersion(), Equals, version.MustParse(test.expectVersion))
c.Check(cfg.Development(), Equals, test.expectDevelopment)
if test.expectUploaded != "" {
p := environs.ToolsStoragePath(version.MustParseBinary(test.expectUploaded))
r, err := s.Conn.Environ.Storage().Get(p)
c.Assert(err, IsNil)
data, err := ioutil.ReadAll(r)
c.Check(err, IsNil)
c.Check(string(data), Equals, test.expectUploaded)
r.Close()
}
}
}
示例2: TestAutoSync
func (s *BootstrapSuite) TestAutoSync(c *gc.C) {
// Prepare a mock storage for testing and store the
// dummy tools in there.
restore := createToolsStore(c)
defer restore()
// Change the tools location to be the test location and also
// the version and ensure their later restoring.
origVersion := version.Current
version.Current.Number = version.MustParse("1.2.3")
defer func() { version.Current = origVersion }()
// Create home with dummy provider and remove all
// of its tools.
env, fake := makeEmptyFakeHome(c)
defer fake.Restore()
// Bootstrap the environment now detects the missing
// tools and automatically synchronizes them from the
// storage above.
ctx := coretesting.Context(c)
code := cmd.Main(&BootstrapCommand{}, ctx, nil)
c.Check(code, gc.Equals, 0)
// Now check the available tools which are the 1.0.0 tools.
checkTools(c, env, v100All)
}
示例3: TestDelayedStop
func (s *UpgraderSuite) TestDelayedStop(c *C) {
defer dummy.SetStorageDelay(0)
tools := s.primeTools(c, version.MustParseBinary("2.0.3-foo-bar"))
s.uploadTools(c, version.MustParseBinary("2.0.5-foo-bar"))
s.uploadTools(c, version.MustParseBinary("2.0.6-foo-bar"))
s.uploadTools(c, version.MustParseBinary("2.0.6-foo-bar"))
s.uploadTools(c, version.MustParseBinary("2.0.7-foo-bar"))
s.poisonVersion(version.MustParseBinary("2.0.7-foo-bar"))
for i, test := range delayedStopTests {
c.Logf("%d. %v", i, test.about)
upgraderKillDelay = test.upgraderKillDelay
dummy.SetStorageDelay(test.storageDelay)
proposed := version.MustParse(test.propose)
s.proposeVersion(c, proposed, true)
u := s.startUpgrader(c, tools)
t0 := time.Now()
err := u.Stop()
d := time.Now().Sub(t0)
if d > 100*time.Millisecond {
c.Errorf("upgrader took took too long: %v", d)
}
if test.err == "" {
c.Check(err, IsNil)
} else {
c.Check(err, ErrorMatches, test.err)
}
}
}
示例4: SetUpTest
func (s *syncToolsSuite) SetUpTest(c *C) {
s.LoggingSuite.SetUpTest(c)
s.origVersion = version.Current
// It's important that this be v1 to match the test data.
version.Current.Number = version.MustParse("1.2.3")
// Create a target environments.yaml and make sure its environment is empty.
s.home = testing.MakeFakeHome(c, `
environments:
test-target:
type: dummy
state-server: false
authorized-keys: "not-really-one"
`)
var err error
s.targetEnv, err = environs.NewFromName("test-target")
c.Assert(err, IsNil)
envtesting.RemoveAllTools(c, s.targetEnv)
// Create a source storage.
s.storage, err = envtesting.NewEC2HTTPTestStorage("127.0.0.1")
c.Assert(err, IsNil)
// Create a local tools directory.
s.localStorage = c.MkDir()
// Populate both with the public tools.
for _, vers := range vAll {
s.storage.PutBinary(vers)
putBinary(c, s.localStorage, vers)
}
s.origLocation = defaultToolsLocation
defaultToolsLocation = s.storage.Location()
}
示例5: toolsStoragePath
func toolsStoragePath(vers string) string {
return environs.ToolsStoragePath(version.Binary{
Number: version.MustParse(vers),
Series: version.Current.Series,
Arch: version.Current.Arch,
})
}
示例6: TestNumberBSON
func (suite) TestNumberBSON(c *C) {
type doc struct {
Version version.Number
}
v := doc{version.MustParse("1.2.3")}
data, err := bson.Marshal(&v)
c.Assert(err, IsNil)
var nv doc
err = bson.Unmarshal(data, &nv)
c.Assert(err, IsNil)
c.Assert(v, Equals, nv)
}
示例7: TestWatchAPIVersion
func (s *upgraderSuite) TestWatchAPIVersion(c *C) {
w, err := s.st.WatchAPIVersion(s.rawMachine.Tag())
c.Assert(err, 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, 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, IsNil)
wc.AssertNoChange()
vers = version.MustParse("10.20.35")
err = statetesting.SetAgentVersion(s.BackingState, vers)
c.Assert(err, IsNil)
wc.AssertOneChange()
statetesting.AssertStop(c, w)
wc.AssertClosed()
}
示例8: TestNumberMarshalUnmarshal
func (suite) TestNumberMarshalUnmarshal(c *C) {
for _, m := range marshallers {
c.Logf("encoding %v", m.name)
type doc struct {
Version version.Number
}
v := doc{version.MustParse("1.2.3")}
data, err := m.marshal(&v)
c.Assert(err, IsNil)
var nv doc
err = m.unmarshal(data, &nv)
c.Assert(err, IsNil)
c.Assert(v, Equals, nv)
}
}
示例9: TestWatchAPIVersion
func (s *upgraderSuite) TestWatchAPIVersion(c *C) {
args := params.Entities{
Entities: []params.Entity{{Tag: s.rawMachine.Tag()}},
}
results, err := s.upgrader.WatchAPIVersion(args)
c.Assert(err, IsNil)
c.Check(results.Results, HasLen, 1)
c.Check(results.Results[0].NotifyWatcherId, Not(Equals), "")
c.Check(results.Results[0].Error, IsNil)
resource := s.resources.Get(results.Results[0].NotifyWatcherId)
c.Check(resource, NotNil)
w := resource.(state.NotifyWatcher)
wc := statetesting.NewNotifyWatcherC(c, s.State, w)
wc.AssertNoChange()
err = statetesting.SetAgentVersion(s.State, version.MustParse("3.4.567.8"))
c.Assert(err, IsNil)
wc.AssertOneChange()
statetesting.AssertStop(c, w)
wc.AssertClosed()
}
示例10: TestAutoSyncLocalSource
func (s *BootstrapSuite) TestAutoSyncLocalSource(c *gc.C) {
// Prepare a tools directory for testing and store the
// dummy tools in there.
source := createToolsSource(c)
// Change the version and ensure its later restoring.
origVersion := version.Current
version.Current.Number = version.MustParse("1.2.3")
defer func() {
version.Current = origVersion
}()
// Create home with dummy provider and remove all
// of its tools.
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{"--source", c.MkDir()})
c.Check(code, gc.Equals, 1)
// Now check that there are no tools available.
_, err := environs.FindAvailableTools(env, version.Current.Major)
c.Assert(err, gc.ErrorMatches, "no tools available")
// Bootstrap the environment with the valid source. This time
// the bootstrapping has to show no error, because the tools
// are automatically synchronized.
ctx = coretesting.Context(c)
code = cmd.Main(&BootstrapCommand{}, ctx, []string{"--source", source})
c.Check(code, gc.Equals, 0)
// Now check the available tools which are the 1.0.0 tools.
checkTools(c, env, v100All)
}
示例11: TestUpgradeJuju
func (s *UpgradeJujuSuite) TestUpgradeJuju(c *C) {
oldVersion := version.Current
uploadTools = mockUploadTools
defer func() {
version.Current = oldVersion
uploadTools = tools.Upload
}()
for i, test := range upgradeJujuTests {
c.Logf("\ntest %d: %s", i, test.about)
s.Reset(c)
// Set up apparent CLI version and initialize the command.
version.Current = version.MustParseBinary(test.currentVersion)
com := &UpgradeJujuCommand{}
if err := coretesting.InitCommand(com, test.args); err != nil {
if test.expectInitErr != "" {
c.Check(err, ErrorMatches, test.expectInitErr)
} else {
c.Check(err, IsNil)
}
continue
}
// Set up state and environ, and run the command.
cfg, err := s.State.EnvironConfig()
c.Assert(err, IsNil)
cfg, err = cfg.Apply(map[string]interface{}{
"agent-version": test.agentVersion,
"development": test.development,
})
c.Assert(err, IsNil)
err = s.State.SetEnvironConfig(cfg)
c.Assert(err, IsNil)
for _, v := range test.private {
vers := version.MustParseBinary(v)
envtesting.MustUploadFakeToolsVersion(s.Conn.Environ.Storage(), vers)
}
for _, v := range test.public {
vers := version.MustParseBinary(v)
storage := s.Conn.Environ.PublicStorage().(environs.Storage)
envtesting.MustUploadFakeToolsVersion(storage, vers)
}
err = com.Run(coretesting.Context(c))
if test.expectErr != "" {
c.Check(err, ErrorMatches, test.expectErr)
continue
} else if !c.Check(err, IsNil) {
continue
}
// Check expected changes to environ/state.
cfg, err = s.State.EnvironConfig()
c.Check(err, IsNil)
agentVersion, ok := cfg.AgentVersion()
c.Check(ok, Equals, true)
c.Check(agentVersion, Equals, version.MustParse(test.expectVersion))
c.Check(cfg.Development(), Equals, test.development)
for _, uploaded := range test.expectUploaded {
vers := version.MustParseBinary(uploaded)
r, err := s.Conn.Environ.Storage().Get(tools.StorageName(vers))
if !c.Check(err, IsNil) {
continue
}
data, err := ioutil.ReadAll(r)
r.Close()
c.Check(err, IsNil)
c.Check(string(data), Equals, uploaded)
}
}
}
示例12:
"state-server": false,
"authorized-keys": "i-am-a-key",
"ca-cert": testing.CACert,
"ca-private-key": "",
}
for k, v := range attrs {
final[k] = v
}
env, err := environs.NewFromAttrs(final)
c.Assert(err, IsNil)
s.env = env
envtesting.RemoveAllTools(c, s.env)
}
var (
v100 = version.MustParse("1.0.0")
v100p64 = version.MustParseBinary("1.0.0-precise-amd64")
v100p32 = version.MustParseBinary("1.0.0-precise-i386")
v100p = []version.Binary{v100p64, v100p32}
v100q64 = version.MustParseBinary("1.0.0-quantal-amd64")
v100q32 = version.MustParseBinary("1.0.0-quantal-i386")
v100q = []version.Binary{v100q64, v100q32}
v100all = append(v100p, v100q...)
v1001 = version.MustParse("1.0.0.1")
v1001p64 = version.MustParseBinary("1.0.0.1-precise-amd64")
v100Xall = append(v100all, v1001p64)
v110 = version.MustParse("1.1.0")
v110p64 = version.MustParseBinary("1.1.0-precise-amd64")
示例13: TestUpgrader
func (s *UpgraderSuite) TestUpgrader(c *C) {
currentTools := s.primeTools(c, version.MustParseBinary("2.0.0-foo-bar"))
// Remove the tools from the storage so that we're sure that the
// uploader isn't trying to fetch them.
resp, err := http.Get(currentTools.URL)
c.Assert(err, IsNil)
err = environs.UnpackTools(s.DataDir(), currentTools, resp.Body)
c.Assert(err, IsNil)
s.removeVersion(c, currentTools.Binary)
var (
u *Upgrader
upgraderDone <-chan error
)
defer func() {
if u != nil {
c.Assert(u.Stop(), IsNil)
}
}()
uploaded := make(map[version.Number]*state.Tools)
for i, test := range upgraderTests {
c.Logf("%d. %s; current version: %v", i, test.about, version.Current)
for _, v := range test.upload {
vers := version.Current
vers.Number = version.MustParse(v)
tools := s.uploadTools(c, vers)
uploaded[vers.Number] = tools
}
if test.current != "" {
version.Current = version.MustParseBinary(test.current)
currentTools, err = environs.ReadTools(s.DataDir(), version.Current)
c.Assert(err, IsNil)
}
if u == nil {
u = s.startUpgrader(c, currentTools)
}
if test.propose != "" {
s.proposeVersion(c, version.MustParse(test.propose), test.devVersion)
s.State.StartSync()
}
if test.upgradeTo == "" {
s.State.StartSync()
assertNothingHappens(c, upgraderDone)
} else {
ug := waitDeath(c, u)
tools := uploaded[version.MustParse(test.upgradeTo)]
c.Check(ug.NewTools, DeepEquals, tools)
c.Check(ug.OldTools.Binary, Equals, version.Current)
c.Check(ug.DataDir, Equals, s.DataDir())
c.Check(ug.AgentName, Equals, "testagent")
// Check that the upgraded version was really downloaded.
data, err := ioutil.ReadFile(filepath.Join(environs.ToolsDir(s.DataDir(), tools.Binary), "jujud"))
c.Assert(err, IsNil)
c.Assert(string(data), Equals, "jujud contents "+tools.Binary.String())
u, upgraderDone = nil, nil
currentTools = tools
version.Current = tools.Binary
}
}
}
示例14:
},
setMachineStatus{"0", params.StatusStarted, ""},
expect{
"simulate the MA started and set the machine status",
M{
"machines": M{
"0": machine0,
},
"services": M{},
},
},
setTools{"0", &tools.Tools{
Binary: version.Binary{
Number: version.MustParse("1.2.3"),
Series: "gutsy",
Arch: "ppc",
},
URL: "http://canonical.com/",
}},
expect{
"simulate the MA setting the version",
M{
"machines": M{
"0": M{
"dns-name": "dummyenv-0.dns",
"instance-id": "dummyenv-0",
"agent-version": "1.2.3",
"agent-state": "started",
"series": "series",
示例15: TestNewest
t2001precise.Binary: t2001precise.URL,
})
}
var newestTests = []struct {
src tools.List
expect tools.List
number version.Number
}{{
src: nil,
expect: nil,
number: version.Zero,
}, {
src: tools.List{t100precise},
expect: tools.List{t100precise},
number: version.MustParse("1.0.0"),
}, {
src: t100all,
expect: t100all,
number: version.MustParse("1.0.0"),
}, {
src: extend(t100all, t190all, t200all),
expect: t200all,
number: version.MustParse("2.0.0"),
}, {
src: tAll,
expect: tools.List{t2001precise},
number: version.MustParse("2.0.0.1"),
}}
func (s *ListSuite) TestNewest(c *gc.C) {