Exemplo n.º 1
0
func (s *StoreSuite) TestPublishErrorFromBzr(c *gc.C) {
	branch := s.dummyBranch(c, "")

	// In TestPublish we ensure that the streams are parsed
	// separately by inserting garbage on stderr. Now make
	// sure that stderr isn't simply trashed, as we want to
	// know about what a real error tells us.
	plugin := fakePlugin{}
	plugin.install(c.MkDir(), `import sys; sys.stderr.write("STDERR STUFF FROM TEST\n"); sys.exit(1)`)
	defer plugin.uninstall()

	err := store.PublishBazaarBranch(s.store, urls, branch.path(), "wrong-rev")
	c.Assert(err, gc.ErrorMatches, "(?s).*STDERR STUFF.*")
}
Exemplo n.º 2
0
func (s *StoreSuite) TestPublishErrorInCharm(c *gc.C) {
	branch := s.dummyBranch(c, "")

	// Corrupt the charm.
	branch.remove("metadata.yaml")
	branch.commit("Removed metadata.yaml.")

	// Attempt to publish the erroneous content.
	err := store.PublishBazaarBranch(s.store, urls, branch.path(), "wrong-rev")
	c.Assert(err, gc.ErrorMatches, ".*/metadata.yaml: no such file or directory")

	// The event should be logged as well, since this was an error in the charm
	// that won't go away and must be communicated to the author.
	event, err := s.store.CharmEvent(urls[0], branch.digest())
	c.Assert(err, gc.IsNil)
	c.Assert(event.Kind, gc.Equals, store.EventPublishError)
	c.Assert(event.Revision, gc.Equals, 0)
	c.Assert(event.Errors, gc.NotNil)
	c.Assert(event.Errors[0], gc.Matches, ".*/metadata.yaml: no such file or directory")
	c.Assert(event.Warnings, gc.IsNil)
}
Exemplo n.º 3
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 := store.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 = store.PublishBazaarBranch(s.store, urls, branch.path(), "wrong-rev")
	c.Assert(err, gc.Equals, store.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 = store.PublishBazaarBranch(s.store, urls, branch.path(), digest1)
	c.Assert(err, gc.Equals, store.ErrRedundantUpdate)

	// Now allow it to publish the new content by providing an unseen revision.
	err = store.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, store.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, store.EventPublished)
		c.Assert(event.Revision, gc.Equals, i)
		c.Assert(event.Errors, gc.IsNil)
		c.Assert(event.Warnings, gc.IsNil)
	}
}