launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/store/lpad_test.go (about)

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