示例#1
0
文件: bundle_test.go 项目: bz2/charm
func (s *BundleSuite) TestReadBundleBytes(c *gc.C) {
	data, err := ioutil.ReadFile(s.bundlePath)
	c.Assert(err, gc.IsNil)

	bundle, err := charm.ReadBundleBytes(data)
	c.Assert(err, gc.IsNil)
	checkDummy(c, bundle, "")
}
示例#2
0
文件: bundle_test.go 项目: bz2/charm
func bundleDir(c *gc.C, dirpath string) *charm.Bundle {
	dir, err := charm.ReadDir(dirpath)
	c.Assert(err, gc.IsNil)
	buf := new(bytes.Buffer)
	err = dir.BundleTo(buf)
	c.Assert(err, gc.IsNil)
	bundle, err := charm.ReadBundleBytes(buf.Bytes())
	c.Assert(err, gc.IsNil)
	return bundle
}
示例#3
0
文件: dir_test.go 项目: bz2/charm
func (s *DirSuite) TestDirSetRevision(c *gc.C) {
	dir := charmtesting.Charms.ClonedDir(c.MkDir(), "dummy")
	c.Assert(dir.Revision(), gc.Equals, 1)
	dir.SetRevision(42)
	c.Assert(dir.Revision(), gc.Equals, 42)

	var b bytes.Buffer
	err := dir.BundleTo(&b)
	c.Assert(err, gc.IsNil)

	bundle, err := charm.ReadBundleBytes(b.Bytes())
	c.Assert(bundle.Revision(), gc.Equals, 42)
}
示例#4
0
func copyCharmDir(dst string, dir *charm.Dir) {
	var b bytes.Buffer
	err := dir.BundleTo(&b)
	if err != nil {
		panic(err)
	}
	bundle, err := charm.ReadBundleBytes(b.Bytes())
	if err != nil {
		panic(err)
	}
	err = bundle.ExpandTo(dst)
	if err != nil {
		panic(err)
	}
}
示例#5
0
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(charmtesting.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)
	}
}
示例#6
0
func (s *StoreSuite) TestPublish(c *gc.C) {
	branch := s.dummyBranch(c, "")

	// Ensure that the streams are parsed separately by inserting
	// garbage on stderr. The wanted information is still there.
	plugin := fakePlugin{}
	plugin.install(c.MkDir(), `import sys; sys.stderr.write("STDERR STUFF FROM TEST\n")`)
	defer plugin.uninstall()

	err := charmstore.PublishBazaarBranch(s.store, urls, branch.path(), "wrong-rev")
	c.Assert(err, gc.IsNil)

	for _, url := range urls {
		info, rc, err := s.store.OpenCharm(url)
		c.Assert(err, gc.IsNil)
		defer rc.Close()
		c.Assert(info.Revision(), gc.Equals, 0)
		c.Assert(info.Meta().Name, gc.Equals, "dummy")

		data, err := ioutil.ReadAll(rc)
		c.Assert(err, gc.IsNil)

		bundle, err := charm.ReadBundleBytes(data)
		c.Assert(err, gc.IsNil)
		c.Assert(bundle.Revision(), gc.Equals, 0)
		c.Assert(bundle.Meta().Name, gc.Equals, "dummy")
	}

	// Attempt to publish the same content again while providing the wrong
	// tip revision. It must pick the real revision from the branch and
	// note this was previously published.
	err = charmstore.PublishBazaarBranch(s.store, urls, branch.path(), "wrong-rev")
	c.Assert(err, gc.Equals, charmstore.ErrRedundantUpdate)

	// Bump the content revision and lie again about the known tip revision.
	// This time, though, pretend it's the same as the real branch revision
	// previously published. It must error and not publish the new revision
	// because it will use the revision provided as a parameter to check if
	// publishing was attempted before. This is the mechanism that enables
	// stopping fast without having to download every single branch. Real
	// revision is picked in the next scan.
	digest1 := branch.digest()
	branch.change()
	err = charmstore.PublishBazaarBranch(s.store, urls, branch.path(), digest1)
	c.Assert(err, gc.Equals, charmstore.ErrRedundantUpdate)

	// Now allow it to publish the new content by providing an unseen revision.
	err = charmstore.PublishBazaarBranch(s.store, urls, branch.path(), "wrong-rev")
	c.Assert(err, gc.IsNil)
	digest2 := branch.digest()

	info, err := s.store.CharmInfo(urls[0])
	c.Assert(err, gc.IsNil)
	c.Assert(info.Revision(), gc.Equals, 1)
	c.Assert(info.Meta().Name, gc.Equals, "dummy")

	// There are two events published, for each of the successful attempts.
	// The failures are ignored given that they are artifacts of the
	// publishing mechanism rather than actual problems.
	_, err = s.store.CharmEvent(urls[0], "wrong-rev")
	c.Assert(err, gc.Equals, charmstore.ErrNotFound)
	for i, digest := range []string{digest1, digest2} {
		event, err := s.store.CharmEvent(urls[0], digest)
		c.Assert(err, gc.IsNil)
		c.Assert(event.Kind, gc.Equals, charmstore.EventPublished)
		c.Assert(event.Revision, gc.Equals, i)
		c.Assert(event.Errors, gc.IsNil)
		c.Assert(event.Warnings, gc.IsNil)
	}
}