func (s *StoreSuite) TestSeriesSolver(c *gc.C) { for _, t := range seriesSolverCharms { url := charm.MustParseURL(fmt.Sprintf("cs:%s/%s", t.series, t.name)) urls := []*charm.URL{url} pub, err := s.store.CharmPublisher(urls, fmt.Sprintf("some-%s-%s-digest", t.series, t.name)) c.Assert(err, gc.IsNil) c.Assert(pub.Revision(), gc.Equals, 0) err = pub.Publish(&FakeCharmDir{}) c.Assert(err, gc.IsNil) } // LTS, then non-LTS, reverse alphabetical order ref, _, err := charm.ParseReference("cs:wordpress") c.Assert(err, gc.IsNil) series, err := s.store.Series(ref) c.Assert(err, gc.IsNil) c.Assert(series, gc.HasLen, 5) c.Check(series[0], gc.Equals, "trusty") c.Check(series[1], gc.Equals, "precise") c.Check(series[2], gc.Equals, "volumetric") c.Check(series[3], gc.Equals, "quantal") c.Check(series[4], gc.Equals, "oneiric") // Ensure that the full charm name matches, not just prefix ref, _, err = charm.ParseReference("cs:mysql") c.Assert(err, gc.IsNil) series, err = s.store.Series(ref) c.Assert(err, gc.IsNil) c.Assert(series, gc.HasLen, 1) c.Check(series[0], gc.Equals, "precise") // No LTS, reverse alphabetical order ref, _, err = charm.ParseReference("cs:zebra") c.Assert(err, gc.IsNil) series, err = s.store.Series(ref) c.Assert(err, gc.IsNil) c.Assert(series, gc.HasLen, 2) c.Check(series[0], gc.Equals, "zef") c.Check(series[1], gc.Equals, "def") }
func (s *Server) resolveURL(url string) (*charm.URL, error) { ref, series, err := charm.ParseReference(url) if err != nil { return nil, err } if series == "" { prefSeries, err := s.store.Series(ref) if err != nil { return nil, err } if len(prefSeries) == 0 { return nil, ErrNotFound } return &charm.URL{Reference: ref, Series: prefSeries[0]}, nil } return &charm.URL{Reference: ref, Series: series}, nil }
func (s *StoreSuite) TestMysqlSeriesSolver(c *gc.C) { for _, t := range mysqlSeriesCharms { var urls []*charm.URL for _, url := range t.urls { urls = append(urls, charm.MustParseURL(url)) } pub, err := s.store.CharmPublisher(urls, t.fakeDigest) c.Assert(err, gc.IsNil) c.Assert(pub.Revision(), gc.Equals, 0) err = pub.Publish(&FakeCharmDir{}) c.Assert(err, gc.IsNil) } ref, _, err := charm.ParseReference("cs:mysql") c.Assert(err, gc.IsNil) series, err := s.store.Series(ref) c.Assert(err, gc.IsNil) c.Assert(series, gc.HasLen, 2) c.Check(series[0], gc.Equals, "precise") c.Check(series[1], gc.Equals, "oneiric") }