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

List command returns a "not logged in message" when not logged in. #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions cmd/charm/charmcmd/list.go
Expand Up @@ -74,6 +74,16 @@ func (c *listCommand) Run(ctxt *cmd.Context) error {
defer client.jar.Save()

if c.users == "" {
csurl := client.ServerURL()
storeurl, err := url.Parse(csurl)
if err != nil {
return errgo.Notef(err, "invalid URL %q for JUJU_CHARMSTORE", csurl)
}
storeurl.Path = strings.TrimSuffix(storeurl.Path, "/") + "/"
if len(client.jar.Cookies(storeurl)) == 0 {
fmt.Fprintf(ctxt.Stdout, "not logged into %v\n", csurl)
return nil
}
resp, err := client.WhoAmI()
if err != nil {
return errgo.Notef(err, "cannot retrieve identity")
Expand Down
10 changes: 9 additions & 1 deletion cmd/charm/charmcmd/list_test.go
Expand Up @@ -8,6 +8,7 @@ import (
qt "github.com/frankban/quicktest"
"gopkg.in/juju/charm.v6"

"github.com/juju/charmstore-client/cmd/charm/charmcmd"
"github.com/juju/charmstore-client/internal/entitytesting"
)

Expand All @@ -24,12 +25,19 @@ func (s *listSuite) Init(c *qt.C) {
s.charmstoreEnv = initCharmstoreEnv(c)
}

func (s *listSuite) TestNotLoggedIn(c *qt.C) {
stdout, stderr, exitCode := run(c.Mkdir(), "list")
c.Assert(stderr, qt.Equals, "")
c.Assert(exitCode, qt.Equals, 0)
c.Assert(stdout, qt.Matches, "not logged into "+charmcmd.ServerURL()+"\n")
}

func (s *listSuite) TestInvalidServerURL(c *qt.C) {
c.Setenv("JUJU_CHARMSTORE", "#%zz")
stdout, stderr, exitCode := run(c.Mkdir(), "list")
c.Assert(stdout, qt.Equals, "")
c.Assert(exitCode, qt.Equals, 1)
c.Assert(stderr, qt.Equals, "ERROR cannot retrieve identity: parse #%zz/v5/whoami: invalid URL escape \"%zz\"\n")
c.Assert(stderr, qt.Equals, "ERROR invalid URL \"#%zz\" for JUJU_CHARMSTORE: parse #%zz: invalid URL escape \"%zz\"\n")
}

func (s *listSuite) TestListUserProvided(c *qt.C) {
Expand Down