当前位置: 首页>>代码示例>>Golang>>正文


Golang charm.MustParseURL函数代码示例

本文整理汇总了Golang中launchpad/net/juju-core/charm.MustParseURL函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParseURL函数的具体用法?Golang MustParseURL怎么用?Golang MustParseURL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MustParseURL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestLockUpdatesExpires

func (s *StoreSuite) TestLockUpdatesExpires(c *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, 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, IsNil)

	// Works due to expiration of previous lock.
	lock2, err := s.store.LockUpdates(urls)
	c.Assert(err, 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, Equals, store.ErrUpdateConflict)
	c.Check(lock3, IsNil)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:31,代码来源:store_test.go

示例2: TestRedundantUpdate

func (s *StoreSuite) TestRedundantUpdate(c *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, IsNil)
	c.Assert(pub.Revision(), Equals, 0)
	err = pub.Publish(&FakeCharmDir{})
	c.Assert(err, IsNil)

	// All charms are already on digest-0.
	pub, err = s.store.CharmPublisher(urls, "digest-0")
	c.Assert(err, ErrorMatches, "charm is up-to-date")
	c.Assert(err, Equals, store.ErrRedundantUpdate)
	c.Assert(pub, IsNil)

	// Now add a second revision just for wordpress-b.
	pub, err = s.store.CharmPublisher(urls[1:], "digest-1")
	c.Assert(err, IsNil)
	c.Assert(pub.Revision(), Equals, 1)
	err = pub.Publish(&FakeCharmDir{})
	c.Assert(err, IsNil)

	// Same digest bumps revision because one of them was old.
	pub, err = s.store.CharmPublisher(urls, "digest-1")
	c.Assert(err, IsNil)
	c.Assert(pub.Revision(), Equals, 2)
	err = pub.Publish(&FakeCharmDir{})
	c.Assert(err, IsNil)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:31,代码来源:store_test.go

示例3: TestInstall

func (s *DeployerSuite) TestInstall(c *C) {
	// Install.
	d := charm.NewDeployer(filepath.Join(c.MkDir(), "deployer"))
	bun := s.bundle(c, func(path string) {
		err := ioutil.WriteFile(filepath.Join(path, "some-file"), []byte("hello"), 0644)
		c.Assert(err, IsNil)
	})
	err := d.Stage(bun, corecharm.MustParseURL("cs:s/c-1"))
	c.Assert(err, IsNil)
	target := charm.NewGitDir(filepath.Join(c.MkDir(), "target"))
	err = d.Deploy(target)
	c.Assert(err, IsNil)

	// Check content.
	data, err := ioutil.ReadFile(filepath.Join(target.Path(), "some-file"))
	c.Assert(err, IsNil)
	c.Assert(string(data), Equals, "hello")
	url, err := charm.ReadCharmURL(target)
	c.Assert(err, IsNil)
	c.Assert(url, DeepEquals, corecharm.MustParseURL("cs:s/c-1"))
	lines, err := target.Log()
	c.Assert(err, IsNil)
	c.Assert(lines, HasLen, 2)
	c.Assert(lines[0], Matches, `[0-9a-f]{7} Deployed charm "cs:s/c-1".`)
	c.Assert(lines[1], Matches, `[0-9a-f]{7} Imported charm "cs:s/c-1" from ".*".`)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:26,代码来源:deployer_test.go

示例4: TestBranchLocation

func (s *StoreSuite) TestBranchLocation(c *C) {
	charmURL := charm.MustParseURL("cs:series/name")
	location := s.store.BranchLocation(charmURL)
	c.Assert(location, Equals, "lp:charms/series/name")

	charmURL = charm.MustParseURL("cs:~user/series/name")
	location = s.store.BranchLocation(charmURL)
	c.Assert(location, Equals, "lp:~user/charms/series/name/trunk")
}
开发者ID:rif,项目名称:golang-stuff,代码行数:9,代码来源:repo_test.go

示例5: TestMissingCharm

func (s *LocalRepoSuite) TestMissingCharm(c *C) {
	_, err := s.repo.Latest(charm.MustParseURL("local:series/zebra"))
	c.Assert(err, ErrorMatches, `no charms found matching "local:series/zebra"`)
	_, err = s.repo.Get(charm.MustParseURL("local:series/zebra"))
	c.Assert(err, ErrorMatches, `no charms found matching "local:series/zebra"`)
	_, err = s.repo.Latest(charm.MustParseURL("local:badseries/zebra"))
	c.Assert(err, ErrorMatches, `no charms found matching "local:badseries/zebra"`)
	_, err = s.repo.Get(charm.MustParseURL("local:badseries/zebra"))
	c.Assert(err, ErrorMatches, `no charms found matching "local:badseries/zebra"`)
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:10,代码来源:repo_test.go

示例6: TestGetCacheImplicitRevision

func (s *StoreSuite) TestGetCacheImplicitRevision(c *C) {
	base := "cs:series/good"
	charmURL := charm.MustParseURL(base)
	revCharmURL := charm.MustParseURL(base + "-23")
	ch, err := s.store.Get(charmURL)
	c.Assert(err, IsNil)
	c.Assert(ch, NotNil)
	c.Assert(s.server.downloads, DeepEquals, []*charm.URL{revCharmURL})
	s.assertCached(c, charmURL)
	s.assertCached(c, revCharmURL)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:11,代码来源:repo_test.go

示例7: TestGetCacheImplicitRevision

func (s *StoreSuite) TestGetCacheImplicitRevision(c *C) {
	os.RemoveAll(s.cache)
	base := "cs:series/blah"
	curl := charm.MustParseURL(base)
	revCurl := charm.MustParseURL(base + "-23")
	ch, err := s.store.Get(curl)
	c.Assert(err, IsNil)
	c.Assert(ch, NotNil)
	c.Assert(s.server.downloads, DeepEquals, []*charm.URL{revCurl})
	s.assertCached(c, curl)
	s.assertCached(c, revCurl)
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:12,代码来源:repo_test.go

示例8: TestMissingRepo

func (s *LocalRepoSuite) TestMissingRepo(c *C) {
	c.Assert(os.RemoveAll(s.repo.Path), IsNil)
	_, err := s.repo.Latest(charm.MustParseURL("local:series/zebra"))
	c.Assert(err, ErrorMatches, `no repository found at ".*"`)
	_, err = s.repo.Get(charm.MustParseURL("local:series/zebra"))
	c.Assert(err, ErrorMatches, `no repository found at ".*"`)
	c.Assert(ioutil.WriteFile(s.repo.Path, nil, 0666), IsNil)
	_, err = s.repo.Latest(charm.MustParseURL("local:series/zebra"))
	c.Assert(err, ErrorMatches, `no repository found at ".*"`)
	_, err = s.repo.Get(charm.MustParseURL("local:series/zebra"))
	c.Assert(err, ErrorMatches, `no repository found at ".*"`)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:12,代码来源:repo_test.go

示例9: TestPublishCharmDistro

func (s *StoreSuite) TestPublishCharmDistro(c *C) {
	branch := s.dummyBranch(c, "~joe/charms/oneiric/dummy/trunk")

	// The Distro call will look for bare /charms, first.
	testing.Server.Response(200, jsonType, []byte("{}"))

	// And then it picks up the tips.
	data := fmt.Sprintf(`[`+
		`["file://%s", "rev1", ["oneiric", "precise"]],`+
		`["file://%s", "%s", []],`+
		`["file:///non-existent/~jeff/charms/precise/bad/trunk", "rev2", []],`+
		`["file:///non-existent/~jeff/charms/precise/bad/skip-me", "rev3", []]`+
		`]`,
		branch.path(), branch.path(), branch.digest())
	testing.Server.Response(200, jsonType, []byte(data))

	apiBase := lpad.APIBase(testing.Server.URL)
	err := store.PublishCharmsDistro(s.store, apiBase)

	// Should have a single failure from the trunk branch that doesn't
	// exist. The redundant update with the known digest should be
	// ignored, and skip-me isn't a supported branch name so it's
	// ignored as well.
	c.Assert(err, ErrorMatches, `1 branch\(es\) failed to be published`)
	berr := err.(store.PublishBranchErrors)[0]
	c.Assert(berr.URL, Equals, "file:///non-existent/~jeff/charms/precise/bad/trunk")
	c.Assert(berr.Err, ErrorMatches, "(?s).*bzr: ERROR: Not a branch.*")

	for _, url := range []string{"cs:oneiric/dummy", "cs:precise/dummy-0", "cs:~joe/oneiric/dummy-0"} {
		dummy, err := s.store.CharmInfo(charm.MustParseURL(url))
		c.Assert(err, IsNil)
		c.Assert(dummy.Meta().Name, Equals, "dummy")
	}

	// The known digest should have been ignored, so revision is still at 0.
	_, err = s.store.CharmInfo(charm.MustParseURL("cs:~joe/oneiric/dummy-1"))
	c.Assert(err, Equals, store.ErrNotFound)

	// bare /charms lookup
	req := testing.Server.WaitRequest()
	c.Assert(req.Method, Equals, "GET")
	c.Assert(req.URL.Path, Equals, "/charms")

	// tips request
	req = testing.Server.WaitRequest()
	c.Assert(req.Method, Equals, "GET")
	c.Assert(req.URL.Path, Equals, "/charms")
	c.Assert(req.Form["ws.op"], DeepEquals, []string{"getBranchTips"})
	c.Assert(req.Form["since"], IsNil)

	// Request must be signed by juju.
	c.Assert(req.Header.Get("Authorization"), Matches, `.*oauth_consumer_key="juju".*`)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:53,代码来源:lpad_test.go

示例10: TestGetBadCache

func (s *StoreSuite) TestGetBadCache(c *C) {
	base := "cs:series/blah"
	curl := charm.MustParseURL(base)
	revCurl := charm.MustParseURL(base + "-23")
	name := charm.Quote(revCurl.String()) + ".charm"
	err := ioutil.WriteFile(filepath.Join(s.cache, name), nil, 0666)
	c.Assert(err, IsNil)
	ch, err := s.store.Get(curl)
	c.Assert(err, IsNil)
	c.Assert(ch, NotNil)
	c.Assert(s.server.downloads, DeepEquals, []*charm.URL{revCurl})
	s.assertCached(c, curl)
	s.assertCached(c, revCurl)
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:14,代码来源:repo_test.go

示例11: TestGetBadCache

func (s *StoreSuite) TestGetBadCache(c *C) {
	c.Assert(os.Mkdir(filepath.Join(charm.CacheDir, "cache"), 0777), IsNil)
	base := "cs:series/good"
	charmURL := charm.MustParseURL(base)
	revCharmURL := charm.MustParseURL(base + "-23")
	name := charm.Quote(revCharmURL.String()) + ".charm"
	err := ioutil.WriteFile(filepath.Join(charm.CacheDir, "cache", name), nil, 0666)
	c.Assert(err, IsNil)
	ch, err := s.store.Get(charmURL)
	c.Assert(err, IsNil)
	c.Assert(ch, NotNil)
	c.Assert(s.server.downloads, DeepEquals, []*charm.URL{revCharmURL})
	s.assertCached(c, charmURL)
	s.assertCached(c, revCharmURL)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:15,代码来源:repo_test.go

示例12: TestCharmDir

func (s *DeploySuite) TestCharmDir(c *C) {
	coretesting.Charms.ClonedDirPath(s.SeriesPath, "dummy")
	err := runDeploy(c, "local:dummy")
	c.Assert(err, IsNil)
	curl := charm.MustParseURL("local:precise/dummy-1")
	s.AssertService(c, "dummy", curl, 1, 0)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:7,代码来源:deploy_test.go

示例13: TestCharmPublishError

func (s *StoreSuite) TestCharmPublishError(c *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, IsNil)
	c.Assert(pub.Revision(), Equals, 0)
	err = pub.Publish(&FakeCharmDir{})
	c.Assert(err, IsNil)

	pub, err = s.store.CharmPublisher(urls, "another-digest")
	c.Assert(err, IsNil)
	c.Assert(pub.Revision(), Equals, 1)
	err = pub.Publish(&FakeCharmDir{error: "beforeWrite"})
	c.Assert(err, ErrorMatches, "beforeWrite")

	pub, err = s.store.CharmPublisher(urls, "another-digest")
	c.Assert(err, IsNil)
	c.Assert(pub.Revision(), Equals, 1)
	err = pub.Publish(&FakeCharmDir{error: "afterWrite"})
	c.Assert(err, ErrorMatches, "afterWrite")

	// Still at the original charm revision that succeeded first.
	info, err := s.store.CharmInfo(url)
	c.Assert(err, IsNil)
	c.Assert(info.Revision(), Equals, 0)
	c.Assert(info.Digest(), Equals, "one-digest")
}
开发者ID:rif,项目名称:golang-stuff,代码行数:30,代码来源:store_test.go

示例14: TestCharmBundle

func (s *DeploySuite) TestCharmBundle(c *C) {
	coretesting.Charms.BundlePath(s.SeriesPath, "dummy")
	err := runDeploy(c, "local:dummy", "some-service-name")
	c.Assert(err, IsNil)
	curl := charm.MustParseURL("local:precise/dummy-1")
	s.AssertService(c, "some-service-name", curl, 1, 0)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:7,代码来源:deploy_test.go

示例15: SetUpTest

func (s *DeployLocalSuite) SetUpTest(c *C) {
	s.JujuConnSuite.SetUpTest(c)
	curl := charm.MustParseURL("local:series/dummy")
	charm, err := s.Conn.PutCharm(curl, s.repo, false)
	c.Assert(err, IsNil)
	s.charm = charm
}
开发者ID:rif,项目名称:golang-stuff,代码行数:7,代码来源:conn_test.go


注:本文中的launchpad/net/juju-core/charm.MustParseURL函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。