Merge lp://staging/~fwereade/pyjuju/go-charm-resolve into lp://staging/pyjuju/go
Proposed by
William Reade
Status: | Merged |
---|---|
Merged at revision: | 198 |
Proposed branch: | lp://staging/~fwereade/pyjuju/go-charm-resolve |
Merge into: | lp://staging/pyjuju/go |
Diff against target: | 0 lines |
To merge this branch: | bzr merge lp://staging/~fwereade/pyjuju/go-charm-resolve |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+108337@code.staging.launchpad.net |
Description of the change
add charm.InferRepo
To post a comment you must log in.
Reviewers: mp+108337_ code.launchpad. net,
Message:
Please take a look.
Description:
add charm.Resolve
https:/ /code.launchpad .net/~fwereade/ juju/go- charm-resolve/ +merge/ 108337
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/6261058/
Affected files:
A [revision details]
M charm/charm.go
M charm/charm_test.go
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>
Index: charm/charm.go
=== modified file 'charm/charm.go'
--- charm/charm.go 2012-05-29 09:31:12 +0000
+++ charm/charm.go 2012-06-01 12:58:01 +0000
@@ -1,6 +1,9 @@
package charm
-import "os"
+import (
+ "fmt"
+ "os"
+)
// The Charm interface is implemented by any type that y{repoPath} Errorf( "unknown schema for charm URL %q", curl))
// may be handled as a charm.
@@ -22,3 +25,22 @@
}
return ReadBundle(path)
}
+
+// Resolve takes a (potentially vaguely-specified) charm name, the path to
the
+// local charm repository, and the environment's default Ubuntu series, and
+// assembles them into a charm URL and a repository which is likely to
contain
+// a charm matching that URL.
+func Resolve(name, repoPath, defaultSeries string) (repo Repository, curl
*URL, err error) {
+ if curl, err = InferURL(name, defaultSeries); err != nil {
+ return
+ }
+ switch curl.Schema {
+ case "cs":
+ repo = Store()
+ case "local":
+ repo = &LocalRepositor
+ default:
+ panic(fmt.
+ }
+ return
+}
Index: charm/charm_test.go charm_test. go' ch.Meta( ).Name, Equals, "dummy")
=== modified file 'charm/
--- charm/charm_test.go 2012-05-29 09:31:12 +0000
+++ charm/charm_test.go 2012-06-01 12:58:01 +0000
@@ -30,6 +30,34 @@
c.Assert(
}
+var resolveTests = []struct { wordpress" }, wordpress" , "anything", "anything", "cs:oneiric/ wordpress" }, wordpress" , "anything", "anything", "cs:oneiric/ wordpress" }, precise/ wordpress" }, oneiric/ wordpress" , "/some/path", "anything", "local: oneiric/ wordpress" }, t.name, t.path, t.series) URL(t.curl) charm.LocalRepo sitory) ; ok { localRepo. Path, Equals, t.path) curl.Schema, Equals, "local") curl.Schema, Equals, "cs") f.Revision( ), Equals, 1) f.Meta( ).Name, Equals, "dummy")
+ name string
+ path string
+ series string
+ curl string
+}{
+ {"wordpress", "anything", "precise", "cs:precise/
+ {"oneiric/
+ {"cs:oneiric/
+ {"local:wordpress", "/some/path", "precise", "local:
+
{"local:
+}
+
+func (s *CharmSuite) TestResolve(c *C) {
+ for _, t := range resolveTests {
+ repo, curl, err := charm.Resolve(
+ c.Assert(err, IsNil)
+ expectCurl := charm.MustParse
+ c.Assert(curl, DeepEquals, expectCurl)
+ if localRepo, ok := repo.(*
+ c.Assert(
+ c.Assert(
+ } else {
+ c.Assert(
+ }
+ }
+}
+
func checkDummy(c *C, f charm.Charm, path string) {
c.Assert(
c.Assert(