~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/gopkg.in/juju/charmstore.v5-unstable/internal/legacy/api_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
        "gopkg.in/juju/charmstore.v5-unstable/internal/legacy"
29
29
        "gopkg.in/juju/charmstore.v5-unstable/internal/router"
30
30
        "gopkg.in/juju/charmstore.v5-unstable/internal/storetesting"
31
 
        "gopkg.in/juju/charmstore.v5-unstable/internal/storetesting/hashtesting"
32
31
        "gopkg.in/juju/charmstore.v5-unstable/internal/storetesting/stats"
33
32
)
34
33
 
101
100
        c.Assert(rec.Body.Bytes(), gc.DeepEquals, archiveBytes[10:101])
102
101
}
103
102
 
 
103
func (s *APISuite) TestGetElidesSeriesFromMultiSeriesCharmMetadata(c *gc.C) {
 
104
        _, ch := s.addPublicCharm(c, "multi-series", "cs:~charmers/multi-series-0")
 
105
        rec := httptesting.DoRequest(c, httptesting.DoRequestParams{
 
106
                Handler: s.srv,
 
107
                URL:     "/charm/~charmers/multi-series",
 
108
        })
 
109
        c.Assert(rec.Code, gc.Equals, http.StatusOK)
 
110
 
 
111
        gotCh, err := charm.ReadCharmArchiveBytes(rec.Body.Bytes())
 
112
        c.Assert(err, gc.IsNil)
 
113
 
 
114
        chMeta := ch.Meta()
 
115
        chMeta.Series = nil
 
116
 
 
117
        c.Assert(gotCh.Meta(), jc.DeepEquals, chMeta)
 
118
}
 
119
 
104
120
func (s *APISuite) TestPostNotAllowed(c *gc.C) {
105
121
        httptesting.AssertJSONCall(c, httptesting.JSONCallParams{
106
122
                Handler:      s.srv,
121
137
                ExpectStatus: http.StatusNotFound,
122
138
                ExpectBody: params.Error{
123
139
                        Code:    params.ErrNotFound,
124
 
                        Message: `no matching charm or bundle for "cs:wordpress"`,
 
140
                        Message: `no matching charm or bundle for cs:wordpress`,
125
141
                },
126
142
        })
127
143
}
284
300
 
285
301
func (s *APISuite) TestAPIInfoWithGatedCharm(c *gc.C) {
286
302
        wordpressURL, _ := s.addPublicCharm(c, "wordpress", "cs:precise/wordpress-0")
287
 
        s.store.SetPerms(&wordpressURL.URL, "read", "bob")
 
303
        s.store.SetPerms(&wordpressURL.URL, "stable.read", "bob")
288
304
        httptesting.AssertJSONCall(c, httptesting.JSONCallParams{
289
305
                Handler:      s.srv,
290
306
                URL:          "/charm-info?charms=" + wordpressURL.URL.String(),
352
368
        }})
353
369
}
354
370
 
355
 
func (s *APISuite) TestSHA256Laziness(c *gc.C) {
356
 
        // TODO frankban: remove this test after updating entities in the
357
 
        // production db with their SHA256 hash value. Entities are updated by
358
 
        // running the cshash256 command.
359
 
        id, ch := s.addPublicCharm(c, "wordpress", "cs:~who/precise/wordpress-0")
360
 
        url := id.String()
361
 
        sum256 := fileSHA256(c, ch.Path)
362
 
 
363
 
        hashtesting.CheckSHA256Laziness(c, s.store, &id.URL, func() {
364
 
                httptesting.AssertJSONCall(c, httptesting.JSONCallParams{
365
 
                        Handler:      s.srv,
366
 
                        URL:          "/charm-info?charms=" + url,
367
 
                        ExpectStatus: http.StatusOK,
368
 
                        ExpectBody: map[string]charmrepo.InfoResponse{
369
 
                                url: {
370
 
                                        CanonicalURL: url,
371
 
                                        Sha256:       sum256,
372
 
                                        Revision:     0,
373
 
                                },
374
 
                        },
375
 
                })
376
 
        })
377
 
}
378
 
 
379
371
var serverStatusTests = []struct {
380
372
        path string
381
373
        code int
410
402
        archive := storetesting.Charms.CharmArchive(c.MkDir(), charmName)
411
403
        err := s.store.AddCharmWithArchive(rurl, archive)
412
404
        c.Assert(err, gc.IsNil)
413
 
        err = s.store.SetPerms(&rurl.URL, "read", params.Everyone, rurl.URL.User)
414
 
        c.Assert(err, gc.IsNil)
 
405
        s.setPublic(c, rurl)
415
406
        return rurl, archive
416
407
}
417
408
 
 
409
func (s *APISuite) setPublic(c *gc.C, rurl *router.ResolvedURL) {
 
410
        err := s.store.SetPerms(&rurl.URL, "stable.read", params.Everyone)
 
411
        c.Assert(err, gc.IsNil)
 
412
        err = s.store.Publish(rurl, params.StableChannel)
 
413
        c.Assert(err, gc.IsNil)
 
414
}
 
415
 
418
416
var serveCharmEventErrorsTests = []struct {
419
417
        about       string
420
418
        url         string
475
473
        c.Assert(err, gc.IsNil)
476
474
 
477
475
        // Retrieve the entities.
478
 
        mysql, err := s.store.FindEntity(mysqlUrl)
 
476
        mysql, err := s.store.FindEntity(mysqlUrl, nil)
479
477
        c.Assert(err, gc.IsNil)
480
 
        riak, err := s.store.FindEntity(riakUrl)
 
478
        riak, err := s.store.FindEntity(riakUrl, nil)
481
479
        c.Assert(err, gc.IsNil)
482
480
 
483
481
        tests := []struct {
600
598
        s.addExtraInfoDigest(c, url2, "digest-2")
601
599
 
602
600
        // Retrieve the most recent revision of the entity.
603
 
        entity, err := s.store.FindEntity(url2)
 
601
        entity, err := s.store.FindEntity(url2, nil)
604
602
        c.Assert(err, gc.IsNil)
605
603
 
606
604
        // Ensure the last revision is correctly returned.