func (s *clientRepoSuite) TestResolveCharm(c *gc.C) { // Add some charms to be resolved later. for _, url := range []string{ "precise/wordpress-1", "trusty/wordpress-2", "precise/mysql-3", "trusty/riak-4", "utopic/riak-5", } { s.UploadCharm(c, url, "wordpress") } // Run the tests. for i, test := range resolveCharmTests { c.Logf("test %d: %s", i, test.about) client := s.APIState.Client() ref, err := charm.ParseURL(test.url) if test.parseErr == "" { if !c.Check(err, jc.ErrorIsNil) { continue } } else { c.Assert(err, gc.NotNil) c.Check(err, gc.ErrorMatches, test.parseErr) continue } curl, err := client.ResolveCharm(ref) if test.resolveErr == "" { c.Assert(err, jc.ErrorIsNil) c.Check(curl.String(), gc.Equals, test.resolved) continue } c.Check(err, gc.ErrorMatches, test.resolveErr) c.Check(curl, gc.IsNil) } }
func (s *clientRepoSuite) TestResolveCharm(c *gc.C) { resolveCharmTests := []struct { about string url string resolved string parseErr string resolveErr string }{{ about: "wordpress resolved", url: "cs:wordpress", resolved: "cs:trusty/wordpress", }, { about: "mysql resolved", url: "cs:mysql", resolved: "cs:precise/mysql", }, { about: "riak resolved", url: "cs:riak", resolved: "cs:trusty/riak", }, { about: "fully qualified char reference", url: "cs:utopic/riak-5", resolved: "cs:utopic/riak-5", }, { about: "charm with series and no revision", url: "cs:precise/wordpress", resolved: "cs:precise/wordpress", }, { about: "fully qualified reference not found", url: "cs:utopic/riak-42", resolveErr: `cannot resolve URL "cs:utopic/riak-42": charm not found`, }, { about: "reference not found", url: "cs:no-such", resolveErr: `cannot resolve URL "cs:no-such": charm or bundle not found`, }, { about: "invalid charm name", url: "cs:", parseErr: `cannot parse URL "cs://": name "" not valid`, }, { about: "local charm", url: "local:wordpress", resolveErr: `only charm store charm references are supported, with cs: schema`, }} // Add some charms to be resolved later. for _, url := range []string{ "precise/wordpress-1", "trusty/wordpress-2", "precise/mysql-3", "trusty/riak-4", "utopic/riak-5", } { s.UploadCharm(c, url, "wordpress") } // Run the tests. for i, test := range resolveCharmTests { c.Logf("test %d: %s", i, test.about) client := s.APIState.Client() ref, err := charm.ParseURL(test.url) if test.parseErr == "" { if c.Check(err, jc.ErrorIsNil) == false { continue } } else { if c.Check(err, gc.NotNil) == false { continue } c.Check(err, gc.ErrorMatches, test.parseErr) continue } curl, err := client.ResolveCharm(ref) if test.resolveErr == "" { if c.Check(err, jc.ErrorIsNil) == false { continue } c.Check(curl.String(), gc.Equals, test.resolved) continue } c.Check(err, gc.ErrorMatches, test.resolveErr) c.Check(curl, gc.IsNil) } }