本文整理汇总了Golang中github.com/juju/core/charm.MustParseURL函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParseURL函数的具体用法?Golang MustParseURL怎么用?Golang MustParseURL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustParseURL函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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"\.`)
}
开发者ID:jkary,项目名称:core,代码行数:30,代码来源:git_deployer_test.go
示例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)
}
开发者ID:jkary,项目名称:core,代码行数:31,代码来源:store_test.go
示例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)
}
开发者ID:jkary,项目名称:core,代码行数:31,代码来源:store_test.go
示例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")
}
开发者ID:jkary,项目名称:core,代码行数:30,代码来源:store_test.go
示例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)
}
开发者ID:jkary,项目名称:core,代码行数:31,代码来源:filter_test.go
示例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)
}
开发者ID:jkary,项目名称:core,代码行数:25,代码来源:store_test.go
示例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)
}
}
开发者ID:jkary,项目名称:core,代码行数:29,代码来源:ssh_test.go
示例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)
}
开发者ID:jkary,项目名称:core,代码行数:7,代码来源:deploy_test.go
示例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)
}
开发者ID:jkary,项目名称:core,代码行数:7,代码来源:deploy_test.go
示例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)
}
开发者ID:jkary,项目名称:core,代码行数:7,代码来源:deploy_test.go
示例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
}
开发者ID:jkary,项目名称:core,代码行数:9,代码来源:export_test.go
示例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".`)
}
开发者ID:jkary,项目名称:core,代码行数:44,代码来源:git_deployer_test.go
示例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)
}
开发者ID:jkary,项目名称:core,代码行数:43,代码来源:store_test.go
示例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"))
}
开发者ID:jkary,项目名称:core,代码行数:10,代码来源:deploy_test.go
示例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
}
开发者ID:jkary,项目名称:core,代码行数:11,代码来源:server_test.go
示例16: TestNetworks
func (s *DeploySuite) TestNetworks(c *gc.C) {
coretesting.Charms.BundlePath(s.SeriesPath, "dummy")
err := runDeploy(c, "local:dummy", "--networks", ", net1, net2 , ")
c.Assert(err, gc.IsNil)
curl := charm.MustParseURL("local:precise/dummy-1")
service, _ := s.AssertService(c, "dummy", curl, 1, 0)
includeNetworks, excludeNetworks, err := service.Networks()
c.Assert(err, gc.IsNil)
c.Assert(includeNetworks, gc.DeepEquals, []string{"net1", "net2"})
c.Assert(excludeNetworks, gc.HasLen, 0)
}
开发者ID:jkary,项目名称:core,代码行数:11,代码来源:deploy_test.go
示例17: TestLockUpdates
func (s *StoreSuite) TestLockUpdates(c *gc.C) {
urlA := charm.MustParseURL("cs:oneiric/wordpress-a")
urlB := charm.MustParseURL("cs:oneiric/wordpress-b")
urls := []*charm.URL{urlA, urlB}
// Lock update of just B to force a partial conflict.
lock1, err := s.store.LockUpdates(urls[1:])
c.Assert(err, gc.IsNil)
// Partially conflicts with locked update above.
lock2, err := s.store.LockUpdates(urls)
c.Check(err, gc.Equals, store.ErrUpdateConflict)
c.Check(lock2, gc.IsNil)
lock1.Unlock()
// Trying again should work since lock1 was released.
lock3, err := s.store.LockUpdates(urls)
c.Assert(err, gc.IsNil)
lock3.Unlock()
}
开发者ID:jkary,项目名称:core,代码行数:21,代码来源:store_test.go
示例18: TestCharmPublisher
func (s *StoreSuite) TestCharmPublisher(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, "some-digest")
c.Assert(err, gc.IsNil)
c.Assert(pub.Revision(), gc.Equals, 0)
err = pub.Publish(testing.Charms.ClonedDir(c.MkDir(), "dummy"))
c.Assert(err, gc.IsNil)
for _, url := range urls {
info, rc, err := s.store.OpenCharm(url)
c.Assert(err, gc.IsNil)
c.Assert(info.Revision(), gc.Equals, 0)
c.Assert(info.Digest(), gc.Equals, "some-digest")
data, err := ioutil.ReadAll(rc)
c.Check(err, gc.IsNil)
err = rc.Close()
c.Assert(err, gc.IsNil)
bundle, err := charm.ReadBundleBytes(data)
c.Assert(err, gc.IsNil)
// The same information must be available by reading the
// full charm data...
c.Assert(bundle.Meta().Name, gc.Equals, "dummy")
c.Assert(bundle.Config().Options["title"].Default, gc.Equals, "My Title")
// ... and the queriable details.
c.Assert(info.Meta().Name, gc.Equals, "dummy")
c.Assert(info.Config().Options["title"].Default, gc.Equals, "My Title")
info2, err := s.store.CharmInfo(url)
c.Assert(err, gc.IsNil)
c.Assert(info2, gc.DeepEquals, info)
}
}
开发者ID:jkary,项目名称:core,代码行数:38,代码来源:store_test.go
示例19: TestDeleteCharm
func (s *StoreSuite) TestDeleteCharm(c *gc.C) {
url := charm.MustParseURL("cs:oneiric/wordpress")
for i := 0; i < 4; i++ {
pub, err := s.store.CharmPublisher([]*charm.URL{url},
fmt.Sprintf("some-digest-%d", i))
c.Assert(err, gc.IsNil)
c.Assert(pub.Revision(), gc.Equals, i)
err = pub.Publish(testing.Charms.ClonedDir(c.MkDir(), "dummy"))
c.Assert(err, gc.IsNil)
}
// Verify charms were published
info, rc, err := s.store.OpenCharm(url)
c.Assert(err, gc.IsNil)
err = rc.Close()
c.Assert(err, gc.IsNil)
c.Assert(info.Revision(), gc.Equals, 3)
// Delete an arbitrary middle revision
url1 := url.WithRevision(1)
infos, err := s.store.DeleteCharm(url1)
c.Assert(err, gc.IsNil)
c.Assert(len(infos), gc.Equals, 1)
// Verify still published
info, rc, err = s.store.OpenCharm(url)
c.Assert(err, gc.IsNil)
err = rc.Close()
c.Assert(err, gc.IsNil)
c.Assert(info.Revision(), gc.Equals, 3)
// Delete all revisions
expectedRevs := map[int]bool{0: true, 2: true, 3: true}
infos, err = s.store.DeleteCharm(url)
c.Assert(err, gc.IsNil)
c.Assert(len(infos), gc.Equals, 3)
for _, deleted := range infos {
// We deleted the charm we expected to
c.Assert(info.Meta().Name, gc.Equals, deleted.Meta().Name)
_, has := expectedRevs[deleted.Revision()]
c.Assert(has, gc.Equals, true)
delete(expectedRevs, deleted.Revision())
}
c.Assert(len(expectedRevs), gc.Equals, 0)
// The charm is all gone
_, _, err = s.store.OpenCharm(url)
c.Assert(err, gc.Not(gc.IsNil))
}
开发者ID:jkary,项目名称:core,代码行数:50,代码来源:store_test.go
示例20: TestLogCharmEventWithRevisionedURL
func (s *StoreSuite) TestLogCharmEventWithRevisionedURL(c *gc.C) {
url := charm.MustParseURL("cs:oneiric/wordpress-0")
event := &store.CharmEvent{
Kind: store.EventPublishError,
Digest: "some-digest",
URLs: []*charm.URL{url},
}
err := s.store.LogCharmEvent(event)
c.Assert(err, gc.ErrorMatches, "LogCharmEvent: got charm URL with revision: cs:oneiric/wordpress-0")
// This may work in the future, but not now.
event, err = s.store.CharmEvent(url, "some-digest")
c.Assert(err, gc.ErrorMatches, "CharmEvent: got charm URL with revision: cs:oneiric/wordpress-0")
c.Assert(event, gc.IsNil)
}
开发者ID:jkary,项目名称:core,代码行数:15,代码来源:store_test.go
注:本文中的github.com/juju/core/charm.MustParseURL函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论