func (s *suite) TestUploadArchiveWithNoSeries(c *gc.C) { id, err := csclient.UploadArchive( s.client, charm.MustParseReference("wordpress"), fakeReader, fakeHash, fakeSize, -1) c.Assert(id, gc.IsNil) c.Assert(err, gc.ErrorMatches, `no series specified in "cs:wordpress"`) }
func (s *suite) TestUploadArchiveWithBadResponse(c *gc.C) { id := charm.MustParseReference("trusty/wordpress") for i, test := range uploadArchiveWithBadResponseTests { c.Logf("test %d: %s", i, test.about) cl := badResponseClient(test.response, test.error) id, err := csclient.UploadArchive(cl, id, fakeReader, fakeHash, fakeSize, -1) c.Assert(id, gc.IsNil) c.Assert(err, gc.ErrorMatches, test.expectError) } }
func (s *suite) TestUploadArchiveWithServerError(c *gc.C) { path := charmRepo.CharmArchivePath(c.MkDir(), "wordpress") body, hash, size := archiveHashAndSize(c, path) defer body.Close() // Send an invalid hash so that the server returns an error. url := charm.MustParseReference("~charmers/trusty/wordpress") id, err := csclient.UploadArchive(s.client, url, body, hash+"mismatch", size, -1) c.Assert(id, gc.IsNil) c.Assert(err, gc.ErrorMatches, "cannot post archive: cannot put archive blob: hash mismatch") }
func (s *suite) checkUploadArchive(c *gc.C, path, url, expectId string) { // Open the archive and calculate its hash and size. body, hash, size := archiveHashAndSize(c, path) defer body.Close() // Post the archive. id, err := csclient.UploadArchive(s.client, charm.MustParseReference(url), body, hash, size, -1) c.Assert(err, gc.IsNil) c.Assert(id.String(), gc.Equals, expectId) // Ensure the entity has been properly added to the db. r, resultingId, resultingHash, resultingSize, err := s.client.GetArchive(id) c.Assert(err, gc.IsNil) defer r.Close() c.Assert(resultingId, gc.DeepEquals, id) c.Assert(resultingHash, gc.Equals, hash) c.Assert(resultingSize, gc.Equals, size) }