5
. "launchpad.net/gocheck"
6
"launchpad.net/juju-core/charm"
7
"launchpad.net/juju-core/store"
8
"launchpad.net/juju-core/testing"
12
var jsonType = map[string]string{
13
"Content-Type": "application/json",
16
func (s *StoreSuite) TestPublishCharmDistro(c *C) {
17
branch := s.dummyBranch(c, "~joe/charms/oneiric/dummy/trunk")
19
// The Distro call will look for bare /charms, first.
20
testing.Server.Response(200, jsonType, []byte("{}"))
22
// And then it picks up the tips.
23
data := fmt.Sprintf(`[`+
24
`["file://%s", "rev1", ["oneiric", "precise"]],`+
25
`["file://%s", "%s", []],`+
26
`["file:///non-existent/~jeff/charms/precise/bad/trunk", "rev2", []],`+
27
`["file:///non-existent/~jeff/charms/precise/bad/skip-me", "rev3", []]`+
29
branch.path(), branch.path(), branch.digest())
30
testing.Server.Response(200, jsonType, []byte(data))
32
apiBase := lpad.APIBase(testing.Server.URL)
33
err := store.PublishCharmsDistro(s.store, apiBase)
35
// Should have a single failure from the trunk branch that doesn't
36
// exist. The redundant update with the known digest should be
37
// ignored, and skip-me isn't a supported branch name so it's
39
c.Assert(err, ErrorMatches, `1 branch\(es\) failed to be published`)
40
berr := err.(store.PublishBranchErrors)[0]
41
c.Assert(berr.URL, Equals, "file:///non-existent/~jeff/charms/precise/bad/trunk")
42
c.Assert(berr.Err, ErrorMatches, "(?s).*bzr: ERROR: Not a branch.*")
44
for _, url := range []string{"cs:oneiric/dummy", "cs:precise/dummy-0", "cs:~joe/oneiric/dummy-0"} {
45
dummy, err := s.store.CharmInfo(charm.MustParseURL(url))
47
c.Assert(dummy.Meta().Name, Equals, "dummy")
50
// The known digest should have been ignored, so revision is still at 0.
51
_, err = s.store.CharmInfo(charm.MustParseURL("cs:~joe/oneiric/dummy-1"))
52
c.Assert(err, Equals, store.ErrNotFound)
54
// bare /charms lookup
55
req := testing.Server.WaitRequest()
56
c.Assert(req.Method, Equals, "GET")
57
c.Assert(req.URL.Path, Equals, "/charms")
60
req = testing.Server.WaitRequest()
61
c.Assert(req.Method, Equals, "GET")
62
c.Assert(req.URL.Path, Equals, "/charms")
63
c.Assert(req.Form["ws.op"], DeepEquals, []string{"getBranchTips"})
64
c.Assert(req.Form["since"], IsNil)
66
// Request must be signed by juju.
67
c.Assert(req.Header.Get("Authorization"), Matches, `.*oauth_consumer_key="juju".*`)