Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update charm dep #10836

Merged
merged 3 commits into from Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Expand Up @@ -147,10 +147,10 @@

[[constraint]]
name = "gopkg.in/juju/charm.v6"
revision = "780719c3e4a68329408cfecf46ed1ee84b530287"
revision = "4e6efee6340bbada7f1e0ce873f33c15254ac2b8"

[[constraint]]
revision = "2adcece4e962a51e0793b8562560cf9da874026f"
revision = "5ca139ef9e6bd138ab2ff3c59aee3c472d12ac89"
name = "gopkg.in/juju/charmrepo.v3"

[[constraint]]
Expand Down
13 changes: 8 additions & 5 deletions api/client_test.go
Expand Up @@ -418,7 +418,8 @@ func (s *clientSuite) TestOpenURIError(c *gc.C) {

func (s *clientSuite) TestOpenCharmFound(c *gc.C) {
client := s.APIState.Client()
curl, ch := addLocalCharm(c, client, "dummy", false)
curl, ch, repoPath := addLocalCharm(c, client, "dummy", false)
defer os.Remove(repoPath)
c.Logf("added local charm as %v", curl)
expected, err := ioutil.ReadFile(ch.Path)
c.Assert(err, jc.ErrorIsNil)
Expand All @@ -434,7 +435,8 @@ func (s *clientSuite) TestOpenCharmFound(c *gc.C) {

func (s *clientSuite) TestOpenCharmFoundWithForceStillSucceeds(c *gc.C) {
client := s.APIState.Client()
curl, ch := addLocalCharm(c, client, "dummy", true)
curl, ch, repoPath := addLocalCharm(c, client, "dummy", true)
defer os.Remove(repoPath)
expected, err := ioutil.ReadFile(ch.Path)
c.Logf("force added local charm as %v", curl)
c.Assert(err, jc.ErrorIsNil)
Expand All @@ -457,12 +459,13 @@ func (s *clientSuite) TestOpenCharmMissing(c *gc.C) {
c.Check(err, gc.ErrorMatches, `.*cannot get charm from state: charm "cs:quantal/spam-3" not found`)
}

func addLocalCharm(c *gc.C, client *api.Client, name string, force bool) (*charm.URL, *charm.CharmArchive) {
charmArchive := testcharms.Repo.CharmArchive(c.MkDir(), name)
func addLocalCharm(c *gc.C, client *api.Client, name string, force bool) (*charm.URL, *charm.CharmArchive, string) {
repo := testcharms.TmpRepo(c)
charmArchive := repo.CharmArchive(repo.Path(), name)
curl := charm.MustParseURL(fmt.Sprintf("local:quantal/%s-%d", charmArchive.Meta().Name, charmArchive.Revision()))
_, err := client.AddLocalCharm(curl, charmArchive, force)
c.Assert(err, jc.ErrorIsNil)
return curl, charmArchive
return curl, charmArchive, repo.Path()
}

func fakeAPIEndpoint(c *gc.C, client *api.Client, address, method string, handle func(http.ResponseWriter, *http.Request)) net.Listener {
Expand Down
5 changes: 4 additions & 1 deletion apiserver/charms_test.go
Expand Up @@ -656,7 +656,10 @@ func (s *charmsSuite) TestGetWorksForControllerMachines(c *gc.C) {

func (s *charmsSuite) TestGetStarReturnsArchiveBytes(c *gc.C) {
// Add the dummy charm.
ch := testcharms.Repo.CharmArchive(c.MkDir(), "dummy")
charmName := "dummy"
repo := testcharms.TmpRepo(c)
defer os.Remove(repo.Path())
ch := repo.CharmArchive(repo.Path(), charmName)
s.uploadRequest(c, s.charmsURI("?series=quantal"), "application/zip", &fileReader{path: ch.Path})

data, err := ioutil.ReadFile(ch.Path)
Expand Down
30 changes: 27 additions & 3 deletions testcharms/charm.go
Expand Up @@ -8,14 +8,19 @@ package testcharms
import (
"archive/zip"
"bytes"
"fmt"
"github.com/juju/utils/fs"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad grouping here... for next time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this somehow got lost. Next time 👍

"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"time"

jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"

"gopkg.in/juju/charm.v6"
"gopkg.in/juju/charmrepo.v3/csclient"
"gopkg.in/juju/charmrepo.v3/csclient/params"
Expand All @@ -25,9 +30,28 @@ import (
)

const defaultSeries = "quantal"
const localCharmRepo = "charm-repo"

// Repo provides access to the test charm repository.
var Repo = testing.NewRepo("charm-repo", defaultSeries)
var Repo = testing.NewRepo(localCharmRepo, defaultSeries)

// TmpRepo provides access to the a tmp repo repository consisting of one charm. Copied from the
// repository under juju/juju
// With this we can make sure that we use the proper level of isolation. In this case the charm repo is not under
// Juju git versioning.
func TmpRepo(c *gc.C) *testing.Repo {
_, file, _, ok := runtime.Caller(0)
if !ok {
panic("cannot get caller")
}
dst := filepath.Join(os.TempDir(), fmt.Sprintf("file-%d", time.Now().UnixNano()))

// With this we ensure only to copy the charm we need
src := filepath.Join(filepath.Dir(file), localCharmRepo, defaultSeries)
err := fs.Copy(src, dst)
c.Assert(err, jc.ErrorIsNil)
return testing.NewRepoFromFullPath(dst, "")
}

// RepoForSeries returns a new charm repository for the specified series.
// Note: this is a bit weird, as it ignores the series if it's NOT kubernetes
Expand All @@ -38,12 +62,12 @@ func RepoForSeries(series string) *testing.Repo {
if series != "kubernetes" {
series = defaultSeries
}
return testing.NewRepo("charm-repo", series)
return testing.NewRepo(localCharmRepo, series)
}

// RepoWithSeries returns a new charm repository for the specified series.
func RepoWithSeries(series string) *testing.Repo {
return testing.NewRepo("charm-repo", series)
return testing.NewRepo(localCharmRepo, series)
}

// CharmstoreClient bridges a charmstore and Juju
Expand Down