Пример #1
0
func (s *MockStore) serveInfo(w http.ResponseWriter, r *http.Request) {
	if metadata := r.Header.Get("Juju-Metadata"); metadata != "" {
		s.Metadata = append(s.Metadata, metadata)
		logger.Infof("Juju metadata: " + metadata)
	}

	r.ParseForm()
	if r.Form.Get("stats") == "0" {
		s.InfoRequestCountNoStats += 1
	} else {
		s.InfoRequestCount += 1
	}

	response := map[string]*charm.InfoResponse{}
	for _, url := range r.Form["charms"] {
		cr := &charm.InfoResponse{}
		response[url] = cr
		charmURL, err := charm.ParseURL(url)
		if err == charm.ErrUnresolvedUrl {
			ref, _, err := charm.ParseReference(url)
			if err != nil {
				panic(err)
			}
			if s.DefaultSeries == "" {
				panic(fmt.Errorf("mock store lacks a default series cannot resolve charm URL: %q", url))
			}
			charmURL = &charm.URL{Reference: ref, Series: s.DefaultSeries}
		}
		switch charmURL.Name {
		case "borken":
			cr.Errors = append(cr.Errors, "badness")
		case "terracotta":
			cr.Errors = append(cr.Errors, "cannot get revision")
		case "unwise":
			cr.Warnings = append(cr.Warnings, "foolishness")
			fallthrough
		default:
			if rev, ok := s.charms[charmURL.WithRevision(-1).String()]; ok {
				if charmURL.Revision == -1 {
					cr.Revision = rev
				} else {
					cr.Revision = charmURL.Revision
				}
				cr.Sha256 = s.bundleSha256
				cr.CanonicalURL = charmURL.String()
			} else {
				cr.Errors = append(cr.Errors, "entry not found")
			}
		}
	}
	data, err := json.Marshal(response)
	if err != nil {
		panic(err)
	}
	w.Header().Set("Content-Type", "application/json")
	_, err = w.Write(data)
	if err != nil {
		panic(err)
	}
}
Пример #2
0
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")
}
Пример #3
0
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
}
Пример #4
0
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")
}