~juju-qa/ubuntu/yakkety/juju/2.0-rc3-again

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/store/lpad_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-04-24 22:34:47 UTC
  • Revision ID: package-import@ubuntu.com-20130424223447-f0qdji7ubnyo0s71
Tags: upstream-1.10.0.1
ImportĀ upstreamĀ versionĀ 1.10.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package store_test
 
2
 
 
3
import (
 
4
        "fmt"
 
5
        . "launchpad.net/gocheck"
 
6
        "launchpad.net/juju-core/charm"
 
7
        "launchpad.net/juju-core/store"
 
8
        "launchpad.net/juju-core/testing"
 
9
        "launchpad.net/lpad"
 
10
)
 
11
 
 
12
var jsonType = map[string]string{
 
13
        "Content-Type": "application/json",
 
14
}
 
15
 
 
16
func (s *StoreSuite) TestPublishCharmDistro(c *C) {
 
17
        branch := s.dummyBranch(c, "~joe/charms/oneiric/dummy/trunk")
 
18
 
 
19
        // The Distro call will look for bare /charms, first.
 
20
        testing.Server.Response(200, jsonType, []byte("{}"))
 
21
 
 
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", []]`+
 
28
                `]`,
 
29
                branch.path(), branch.path(), branch.digest())
 
30
        testing.Server.Response(200, jsonType, []byte(data))
 
31
 
 
32
        apiBase := lpad.APIBase(testing.Server.URL)
 
33
        err := store.PublishCharmsDistro(s.store, apiBase)
 
34
 
 
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
 
38
        // ignored as well.
 
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.*")
 
43
 
 
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))
 
46
                c.Assert(err, IsNil)
 
47
                c.Assert(dummy.Meta().Name, Equals, "dummy")
 
48
        }
 
49
 
 
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)
 
53
 
 
54
        // bare /charms lookup
 
55
        req := testing.Server.WaitRequest()
 
56
        c.Assert(req.Method, Equals, "GET")
 
57
        c.Assert(req.URL.Path, Equals, "/charms")
 
58
 
 
59
        // tips request
 
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)
 
65
 
 
66
        // Request must be signed by juju.
 
67
        c.Assert(req.Header.Get("Authorization"), Matches, `.*oauth_consumer_key="juju".*`)
 
68
}