func (br *bundleReader) AddCustomBundle(c *gc.C, url *corecharm.URL, customize func(path string)) charm.BundleInfo { base := c.MkDir() dirpath := testcharms.Repo.ClonedDirPath(base, "dummy") if customize != nil { customize(dirpath) } dir, err := corecharm.ReadCharmDir(dirpath) c.Assert(err, jc.ErrorIsNil) err = dir.SetDiskRevision(url.Revision) c.Assert(err, jc.ErrorIsNil) bunpath := filepath.Join(base, "bundle") file, err := os.Create(bunpath) c.Assert(err, jc.ErrorIsNil) defer file.Close() err = dir.ArchiveTo(file) c.Assert(err, jc.ErrorIsNil) bundle, err := corecharm.ReadCharmArchive(bunpath) c.Assert(err, jc.ErrorIsNil) return br.AddBundle(c, url, bundle) }
func (s *BundlesDirSuite) AddCharm(c *gc.C) (charm.BundleInfo, *state.Charm, []byte) { curl := corecharm.MustParseURL("cs:quantal/dummy-1") storagePath := "dummy-1" bunpath := testcharms.Repo.CharmArchivePath(c.MkDir(), "dummy") bun, err := corecharm.ReadCharmArchive(bunpath) c.Assert(err, jc.ErrorIsNil) bundata, hash := readHash(c, bunpath) sch, err := s.State.AddCharm(bun, curl, storagePath, hash) c.Assert(err, jc.ErrorIsNil) apiCharm, err := s.uniter.Charm(sch.URL()) c.Assert(err, jc.ErrorIsNil) surlBad, err := url.Parse(s.URL("/some/charm.bundle?bad")) c.Assert(err, jc.ErrorIsNil) surlGood, err := url.Parse(s.URL("/some/charm.bundle?good")) c.Assert(err, jc.ErrorIsNil) mock := &mockArchiveURLCharm{ apiCharm, []*url.URL{surlBad, surlGood}, } return mock, sch, bundata }