本文整理汇总了Golang中github.com/juju/core/charm.MustParseURL函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParseURL函数的具体用法?Golang MustParseURL怎么用?Golang MustParseURL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustParseURL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestInstall
func (s *GitDeployerSuite) TestInstall(c *gc.C) {
// Prepare.
info := s.bundles.AddCustomBundle(c, corecharm.MustParseURL("cs:s/c-1"), func(path string) {
err := ioutil.WriteFile(filepath.Join(path, "some-file"), []byte("hello"), 0644)
c.Assert(err, gc.IsNil)
})
err := s.deployer.Stage(info, nil)
c.Assert(err, gc.IsNil)
checkCleanup(c, s.deployer)
// Install.
err = s.deployer.Deploy()
c.Assert(err, gc.IsNil)
checkCleanup(c, s.deployer)
// Check content.
data, err := ioutil.ReadFile(filepath.Join(s.targetPath, "some-file"))
c.Assert(err, gc.IsNil)
c.Assert(string(data), gc.Equals, "hello")
target := charm.NewGitDir(s.targetPath)
url, err := target.ReadCharmURL()
c.Assert(err, gc.IsNil)
c.Assert(url, gc.DeepEquals, corecharm.MustParseURL("cs:s/c-1"))
lines, err := target.Log()
c.Assert(err, gc.IsNil)
c.Assert(lines, gc.HasLen, 2)
c.Assert(lines[0], gc.Matches, `[0-9a-f]{7} Deployed charm "cs:s/c-1"\.`)
c.Assert(lines[1], gc.Matches, `[0-9a-f]{7} Imported charm "cs:s/c-1"\.`)
}
示例2: TestLockUpdatesExpires
func (s *StoreSuite) TestLockUpdatesExpires(c *gc.C) {
urlA := charm.MustParseURL("cs:oneiric/wordpress-a")
urlB := charm.MustParseURL("cs:oneiric/wordpress-b")
urls := []*charm.URL{urlA, urlB}
// Initiate an update of B only to force a partial conflict.
lock1, err := s.store.LockUpdates(urls[1:])
c.Assert(err, gc.IsNil)
// Hack time to force an expiration.
locks := s.Session.DB("juju").C("locks")
selector := bson.M{"_id": urlB.String()}
update := bson.M{"time": bson.Now().Add(-store.UpdateTimeout - 10e9)}
err = locks.Update(selector, update)
c.Check(err, gc.IsNil)
// Works due to expiration of previous lock.
lock2, err := s.store.LockUpdates(urls)
c.Assert(err, gc.IsNil)
defer lock2.Unlock()
// The expired lock was forcefully killed. Unlocking it must
// not interfere with lock2 which is still alive.
lock1.Unlock()
// The above statement was a NOOP and lock2 is still in effect,
// so attempting another lock must necessarily fail.
lock3, err := s.store.LockUpdates(urls)
c.Check(err, gc.Equals, store.ErrUpdateConflict)
c.Check(lock3, gc.IsNil)
}
示例3: TestRedundantUpdate
func (s *StoreSuite) TestRedundantUpdate(c *gc.C) {
urlA := charm.MustParseURL("cs:oneiric/wordpress-a")
urlB := charm.MustParseURL("cs:oneiric/wordpress-b")
urls := []*charm.URL{urlA, urlB}
pub, err := s.store.CharmPublisher(urls, "digest-0")
c.Assert(err, gc.IsNil)
c.Assert(pub.Revision(), gc.Equals, 0)
err = pub.Publish(&FakeCharmDir{})
c.Assert(err, gc.IsNil)
// All charms are already on digest-0.
pub, err = s.store.CharmPublisher(urls, "digest-0")
c.Assert(err, gc.ErrorMatches, "charm is up-to-date")
c.Assert(err, gc.Equals, store.ErrRedundantUpdate)
c.Assert(pub, gc.IsNil)
// Now add a second revision just for wordpress-b.
pub, err = s.store.CharmPublisher(urls[1:], "digest-1")
c.Assert(err, gc.IsNil)
c.Assert(pub.Revision(), gc.Equals, 1)
err = pub.Publish(&FakeCharmDir{})
c.Assert(err, gc.IsNil)
// Same digest bumps revision because one of them was old.
pub, err = s.store.CharmPublisher(urls, "digest-1")
c.Assert(err, gc.IsNil)
c.Assert(pub.Revision(), gc.Equals, 2)
err = pub.Publish(&FakeCharmDir{})
c.Assert(err, gc.IsNil)
}
示例4: TestCharmPublishError
func (s *StoreSuite) TestCharmPublishError(c *gc.C) {
url := charm.MustParseURL("cs:oneiric/wordpress")
urls := []*charm.URL{url}
// Publish one successfully to bump the revision so we can
// make sure it is being correctly set below.
pub, err := s.store.CharmPublisher(urls, "one-digest")
c.Assert(err, gc.IsNil)
c.Assert(pub.Revision(), gc.Equals, 0)
err = pub.Publish(&FakeCharmDir{})
c.Assert(err, gc.IsNil)
pub, err = s.store.CharmPublisher(urls, "another-digest")
c.Assert(err, gc.IsNil)
c.Assert(pub.Revision(), gc.Equals, 1)
err = pub.Publish(&FakeCharmDir{error: "beforeWrite"})
c.Assert(err, gc.ErrorMatches, "beforeWrite")
pub, err = s.store.CharmPublisher(urls, "another-digest")
c.Assert(err, gc.IsNil)
c.Assert(pub.Revision(), gc.Equals, 1)
err = pub.Publish(&FakeCharmDir{error: "afterWrite"})
c.Assert(err, gc.ErrorMatches, "afterWrite")
// Still at the original charm revision that succeeded first.
info, err := s.store.CharmInfo(url)
c.Assert(err, gc.IsNil)
c.Assert(info.Revision(), gc.Equals, 0)
c.Assert(info.Digest(), gc.Equals, "one-digest")
}
示例5: TestCharmErrorEvents
func (s *FilterSuite) TestCharmErrorEvents(c *gc.C) {
f, err := newFilter(s.uniter, s.unit.Tag())
c.Assert(err, gc.IsNil)
defer f.Stop() // no AssertStop, we test for an error below
assertNoChange := func() {
s.BackingState.StartSync()
select {
case <-f.ConfigEvents():
c.Fatalf("unexpected config event")
case <-time.After(coretesting.ShortWait):
}
}
// Check setting an invalid charm URL does not send events.
err = f.SetCharm(charm.MustParseURL("cs:missing/one-1"))
c.Assert(err, gc.Equals, tomb.ErrDying)
assertNoChange()
s.assertFilterDies(c, f)
// Filter died after the error, so restart it.
f, err = newFilter(s.uniter, s.unit.Tag())
c.Assert(err, gc.IsNil)
defer f.Stop() // no AssertStop, we test for an error below
// Check with a nil charm URL, again no changes.
err = f.SetCharm(nil)
c.Assert(err, gc.Equals, tomb.ErrDying)
assertNoChange()
s.assertFilterDies(c, f)
}
示例6: TestConflictingUpdate
func (s *StoreSuite) TestConflictingUpdate(c *gc.C) {
// This test checks that if for whatever reason the locking
// safety-net fails, adding two charms in parallel still
// results in a sane outcome.
url := charm.MustParseURL("cs:oneiric/wordpress")
urls := []*charm.URL{url}
pub1, err := s.store.CharmPublisher(urls, "some-digest")
c.Assert(err, gc.IsNil)
c.Assert(pub1.Revision(), gc.Equals, 0)
pub2, err := s.store.CharmPublisher(urls, "some-digest")
c.Assert(err, gc.IsNil)
c.Assert(pub2.Revision(), gc.Equals, 0)
// The first publishing attempt should work.
err = pub2.Publish(&FakeCharmDir{})
c.Assert(err, gc.IsNil)
// Attempting to finish the second attempt should break,
// since it lost the race and the given revision is already
// in place.
err = pub1.Publish(&FakeCharmDir{})
c.Assert(err, gc.Equals, store.ErrUpdateConflict)
}
示例7: TestSSHCommand
func (s *SSHSuite) TestSSHCommand(c *gc.C) {
m := s.makeMachines(3, c, true)
ch := coretesting.Charms.Dir("dummy")
curl := charm.MustParseURL(
fmt.Sprintf("local:quantal/%s-%d", ch.Meta().Name, ch.Revision()),
)
bundleURL, err := url.Parse("http://bundles.testing.invalid/dummy-1")
c.Assert(err, gc.IsNil)
dummy, err := s.State.AddCharm(ch, curl, bundleURL, "dummy-1-sha256")
c.Assert(err, gc.IsNil)
srv := s.AddTestingService(c, "mysql", dummy)
s.addUnit(srv, m[0], c)
srv = s.AddTestingService(c, "mongodb", dummy)
s.addUnit(srv, m[1], c)
s.addUnit(srv, m[2], c)
for i, t := range sshTests {
c.Logf("test %d: %s -> %s\n", i, t.about, t.args)
ctx := coretesting.Context(c)
jujucmd := cmd.NewSuperCommand(cmd.SuperCommandParams{})
jujucmd.Register(envcmd.Wrap(&SSHCommand{}))
code := cmd.Main(jujucmd, ctx, t.args)
c.Check(code, gc.Equals, 0)
c.Check(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "")
c.Check(ctx.Stdout.(*bytes.Buffer).String(), gc.Equals, t.result)
}
}
示例8: TestCharmDir
func (s *DeploySuite) TestCharmDir(c *gc.C) {
coretesting.Charms.ClonedDirPath(s.SeriesPath, "dummy")
err := runDeploy(c, "local:dummy")
c.Assert(err, gc.IsNil)
curl := charm.MustParseURL("local:precise/dummy-1")
s.AssertService(c, "dummy", curl, 1, 0)
}
示例9: TestNumUnits
func (s *DeploySuite) TestNumUnits(c *gc.C) {
coretesting.Charms.BundlePath(s.SeriesPath, "dummy")
err := runDeploy(c, "local:dummy", "-n", "13")
c.Assert(err, gc.IsNil)
curl := charm.MustParseURL("local:precise/dummy-1")
s.AssertService(c, "dummy", curl, 13, 0)
}
示例10: TestSubordinateCharm
func (s *DeploySuite) TestSubordinateCharm(c *gc.C) {
coretesting.Charms.BundlePath(s.SeriesPath, "logging")
err := runDeploy(c, "local:logging")
c.Assert(err, gc.IsNil)
curl := charm.MustParseURL("local:precise/logging-1")
s.AssertService(c, "logging", curl, 0, 0)
}
示例11: addCharm
func addCharm(c *gc.C, st *State, series string, ch charm.Charm) *Charm {
ident := fmt.Sprintf("%s-%s-%d", series, ch.Meta().Name, ch.Revision())
curl := charm.MustParseURL("local:" + series + "/" + ident)
bundleURL, err := url.Parse("http://bundles.testing.invalid/" + ident)
c.Assert(err, gc.IsNil)
sch, err := st.AddCharm(ch, curl, bundleURL, ident+"-sha256")
c.Assert(err, gc.IsNil)
return sch
}
示例12: TestUpgrade
func (s *GitDeployerSuite) TestUpgrade(c *gc.C) {
// Install.
info1 := s.bundles.AddCustomBundle(c, corecharm.MustParseURL("cs:s/c-1"), func(path string) {
err := ioutil.WriteFile(filepath.Join(path, "some-file"), []byte("hello"), 0644)
c.Assert(err, gc.IsNil)
err = os.Symlink("./some-file", filepath.Join(path, "a-symlink"))
c.Assert(err, gc.IsNil)
})
err := s.deployer.Stage(info1, nil)
c.Assert(err, gc.IsNil)
err = s.deployer.Deploy()
c.Assert(err, gc.IsNil)
// Upgrade.
info2 := s.bundles.AddCustomBundle(c, corecharm.MustParseURL("cs:s/c-2"), func(path string) {
err := ioutil.WriteFile(filepath.Join(path, "some-file"), []byte("goodbye"), 0644)
c.Assert(err, gc.IsNil)
err = ioutil.WriteFile(filepath.Join(path, "a-symlink"), []byte("not any more!"), 0644)
c.Assert(err, gc.IsNil)
})
err = s.deployer.Stage(info2, nil)
c.Assert(err, gc.IsNil)
checkCleanup(c, s.deployer)
err = s.deployer.Deploy()
c.Assert(err, gc.IsNil)
checkCleanup(c, s.deployer)
// Check content.
data, err := ioutil.ReadFile(filepath.Join(s.targetPath, "some-file"))
c.Assert(err, gc.IsNil)
c.Assert(string(data), gc.Equals, "goodbye")
data, err = ioutil.ReadFile(filepath.Join(s.targetPath, "a-symlink"))
c.Assert(err, gc.IsNil)
c.Assert(string(data), gc.Equals, "not any more!")
target := charm.NewGitDir(s.targetPath)
url, err := target.ReadCharmURL()
c.Assert(err, gc.IsNil)
c.Assert(url, gc.DeepEquals, corecharm.MustParseURL("cs:s/c-2"))
lines, err := target.Log()
c.Assert(err, gc.IsNil)
c.Assert(lines, gc.HasLen, 5)
c.Assert(lines[0], gc.Matches, `[0-9a-f]{7} Upgraded charm to "cs:s/c-2".`)
}
示例13: TestRevisioning
func (s *StoreSuite) TestRevisioning(c *gc.C) {
urlA := charm.MustParseURL("cs:oneiric/wordpress-a")
urlB := charm.MustParseURL("cs:oneiric/wordpress-b")
urls := []*charm.URL{urlA, urlB}
tests := []struct {
urls []*charm.URL
data string
}{
{urls[0:], "charm-revision-0"},
{urls[1:], "charm-revision-1"},
{urls[0:], "charm-revision-2"},
}
for i, t := range tests {
pub, err := s.store.CharmPublisher(t.urls, fmt.Sprintf("digest-%d", i))
c.Assert(err, gc.IsNil)
c.Assert(pub.Revision(), gc.Equals, i)
err = pub.Publish(&FakeCharmDir{})
c.Assert(err, gc.IsNil)
}
for i, t := range tests {
for _, url := range t.urls {
url = url.WithRevision(i)
info, rc, err := s.store.OpenCharm(url)
c.Assert(err, gc.IsNil)
data, err := ioutil.ReadAll(rc)
cerr := rc.Close()
c.Assert(info.Revision(), gc.Equals, i)
c.Assert(url.Revision, gc.Equals, i) // Untouched.
c.Assert(cerr, gc.IsNil)
c.Assert(string(data), gc.Equals, string(t.data))
c.Assert(err, gc.IsNil)
}
}
info, rc, err := s.store.OpenCharm(urlA.WithRevision(1))
c.Assert(err, gc.Equals, store.ErrNotFound)
c.Assert(info, gc.IsNil)
c.Assert(rc, gc.IsNil)
}
示例14: TestConstraints
func (s *DeploySuite) TestConstraints(c *gc.C) {
coretesting.Charms.BundlePath(s.SeriesPath, "dummy")
err := runDeploy(c, "local:dummy", "--constraints", "mem=2G cpu-cores=2")
c.Assert(err, gc.IsNil)
curl := charm.MustParseURL("local:precise/dummy-1")
service, _ := s.AssertService(c, "dummy", curl, 1, 0)
cons, err := service.Constraints()
c.Assert(err, gc.IsNil)
c.Assert(cons, gc.DeepEquals, constraints.MustParse("mem=2G cpu-cores=2"))
}
示例15: prepareServer
func (s *StoreSuite) prepareServer(c *gc.C) (*store.Server, *charm.URL) {
curl := charm.MustParseURL("cs:precise/wordpress")
pub, err := s.store.CharmPublisher([]*charm.URL{curl}, "some-digest")
c.Assert(err, gc.IsNil)
err = pub.Publish(&FakeCharmDir{})
c.Assert(err, gc.IsNil)
server, err := store.NewServer(s.store)
c.Assert(err, gc.IsNil)
return server, curl
}