Skip to content

Commit

Permalink
Replaced -e/--environment by -m/--model in code, tests, docs, comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiamac committed Jan 20, 2016
1 parent 07a7146 commit 251c905
Show file tree
Hide file tree
Showing 35 changed files with 317 additions and 289 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pass an additional flag, `--upload-tools` to instruct the `juju` client to build
a set of tools from source and upload them to the environment as part of the
bootstrap process.

juju bootstrap -e your-environment --upload-tools {--debug}
juju bootstrap -m your-model --upload-tools {--debug}


Installing bash completion for juju
Expand Down
8 changes: 4 additions & 4 deletions cmd/envcmd/environmentcommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ func (c *EnvCommandBase) ConnectionName() string {
// EnvironCommand wrapper.
type WrapEnvOption func(*environCommandWrapper)

// EnvSkipFlags instructs the wrapper to skip --e and
// --environment flag definition.
// EnvSkipFlags instructs the wrapper to skip --m and
// --model flag definition.
func EnvSkipFlags(w *environCommandWrapper) {
w.skipFlags = true
}
Expand Down Expand Up @@ -369,8 +369,8 @@ type environCommandWrapper struct {

func (w *environCommandWrapper) SetFlags(f *gnuflag.FlagSet) {
if !w.skipFlags {
f.StringVar(&w.envName, "e", "", "juju environment to operate in")
f.StringVar(&w.envName, "environment", "", "")
f.StringVar(&w.envName, "m", "", "juju model to operate in")
f.StringVar(&w.envName, "model", "", "")
}
w.EnvironCommand.SetFlags(f)
}
Expand Down
22 changes: 13 additions & 9 deletions cmd/envcmd/environmentcommand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package envcmd_test

import (
"fmt"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -77,14 +78,14 @@ func (s *EnvironmentCommandSuite) TestGetDefaultEnvironmentBothSet(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
}

func (s *EnvironmentCommandSuite) TestEnvironCommandInitExplicit(c *gc.C) {
func (s *EnvironmentCommandSuite) TestEnvironCommandMInitExplicit(c *gc.C) {
// Take environment name from command line arg.
testEnsureEnvName(c, "explicit", "-e", "explicit")
testEnsureEnvName(c, "explicit", "-m", "explicit")
}

func (s *EnvironmentCommandSuite) TestEnvironCommandInitExplicitLongForm(c *gc.C) {
func (s *EnvironmentCommandSuite) TestEnvironCommandModelInitExplicit(c *gc.C) {
// Take environment name from command line arg.
testEnsureEnvName(c, "explicit", "--environment", "explicit")
testEnsureEnvName(c, "explicit", "--model", "explicit")
}

func (s *EnvironmentCommandSuite) TestEnvironCommandInitMultipleConfigs(c *gc.C) {
Expand Down Expand Up @@ -161,8 +162,11 @@ func (s *EnvironmentCommandSuite) TestCompatVersionInvalid(c *gc.C) {
func (s *EnvironmentCommandSuite) TestWrapWithoutFlags(c *gc.C) {
cmd := new(testCommand)
wrapped := envcmd.Wrap(cmd, envcmd.EnvSkipFlags)
err := cmdtesting.InitCommand(wrapped, []string{"-e", "testenv"})
c.Assert(err, gc.ErrorMatches, "flag provided but not defined: -e")
args := []string{"-m", "testenv"}
err := cmdtesting.InitCommand(wrapped, args)
// 1st position is always the flag
msg := fmt.Sprintf("flag provided but not defined: %v", args[0])
c.Assert(err, gc.ErrorMatches, msg)
}

type testCommand struct {
Expand Down Expand Up @@ -220,15 +224,15 @@ func (s *ConnectionEndpointSuite) SetUpTest(c *gc.C) {
}

func (s *ConnectionEndpointSuite) TestAPIEndpointInStoreCached(c *gc.C) {
cmd, err := initTestCommand(c, "-e", "env-name")
cmd, err := initTestCommand(c, "-m", "env-name")
c.Assert(err, jc.ErrorIsNil)
endpoint, err := cmd.ConnectionEndpoint(false)
c.Assert(err, jc.ErrorIsNil)
c.Assert(endpoint, gc.DeepEquals, s.endpoint)
}

func (s *ConnectionEndpointSuite) TestAPIEndpointForEnvSuchName(c *gc.C) {
cmd, err := initTestCommand(c, "-e", "no-such-env")
cmd, err := initTestCommand(c, "-m", "no-such-env")
c.Assert(err, jc.ErrorIsNil)
_, err = cmd.ConnectionEndpoint(false)
c.Assert(err, jc.Satisfies, errors.IsNotFound)
Expand All @@ -250,7 +254,7 @@ func (s *ConnectionEndpointSuite) TestAPIEndpointRefresh(c *gc.C) {
return new(closer), nil
})

cmd, err := initTestCommand(c, "-e", "env-name")
cmd, err := initTestCommand(c, "-m", "env-name")
c.Assert(err, jc.ErrorIsNil)
endpoint, err := cmd.ConnectionEndpoint(true)
c.Assert(err, jc.ErrorIsNil)
Expand Down
71 changes: 38 additions & 33 deletions cmd/juju/action/defined_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ func (s *DefinedSuite) TestInit(c *gc.C) {
}}

for i, t := range tests {
c.Logf("test %d should %s: juju actions defined %s", i,
t.should, strings.Join(t.args, " "))
s.wrappedCommand, s.command = action.NewDefinedCommand()
args := append([]string{"-e", "dummyenv"}, t.args...)
err := testing.InitCommand(s.wrappedCommand, args)
if t.expectedErr == "" {
c.Check(s.command.ServiceTag(), gc.Equals, t.expectedSvc)
c.Check(s.command.FullSchema(), gc.Equals, t.expectedOutputSchema)
} else {
c.Check(err, gc.ErrorMatches, t.expectedErr)
for _, modelFlag := range s.modelFlags {
c.Logf("test %d should %s: juju actions defined %s", i,
t.should, strings.Join(t.args, " "))
s.wrappedCommand, s.command = action.NewDefinedCommand()
args := append([]string{modelFlag, "dummyenv"}, t.args...)
err := testing.InitCommand(s.wrappedCommand, args)
if t.expectedErr == "" {
c.Check(s.command.ServiceTag(), gc.Equals, t.expectedSvc)
c.Check(s.command.FullSchema(), gc.Equals, t.expectedOutputSchema)
} else {
c.Check(err, gc.ErrorMatches, t.expectedErr)
}
}
}
}
Expand Down Expand Up @@ -116,34 +118,37 @@ func (s *DefinedSuite) TestRun(c *gc.C) {
}}

for i, t := range tests {
func() {
c.Logf("test %d should %s", i, t.should)
for _, modelFlag := range s.modelFlags {
func() {
c.Logf("test %d should %s", i, t.should)

fakeClient := &fakeAPIClient{charmActions: t.withCharmActions}
if t.withAPIErr != "" {
fakeClient.apiErr = errors.New(t.withAPIErr)
}
restore := s.patchAPIClient(fakeClient)
defer restore()
fakeClient := &fakeAPIClient{charmActions: t.withCharmActions}
if t.withAPIErr != "" {
fakeClient.apiErr = errors.New(t.withAPIErr)
}
restore := s.patchAPIClient(fakeClient)
defer restore()

args := append([]string{"-e", "dummyenv"}, t.withArgs...)
s.wrappedCommand, s.command = action.NewDefinedCommand()
ctx, err := testing.RunCommand(c, s.wrappedCommand, args...)
args := append([]string{modelFlag, "dummyenv"}, t.withArgs...)
s.wrappedCommand, s.command = action.NewDefinedCommand()
ctx, err := testing.RunCommand(c, s.wrappedCommand, args...)

if t.expectedErr != "" || t.withAPIErr != "" {
c.Check(err, gc.ErrorMatches, t.expectedErr)
} else {
c.Assert(err, gc.IsNil)
result := ctx.Stdout.(*bytes.Buffer).Bytes()
if t.expectFullSchema {
checkFullSchema(c, t.withCharmActions, result)
} else if t.expectNoResults {
c.Check(string(result), gc.Matches, t.expectMessage+"(?sm).*")
if t.expectedErr != "" || t.withAPIErr != "" {
c.Check(err, gc.ErrorMatches, t.expectedErr)
} else {
checkSimpleSchema(c, t.withCharmActions, result)
c.Assert(err, gc.IsNil)
result := ctx.Stdout.(*bytes.Buffer).Bytes()
if t.expectFullSchema {
checkFullSchema(c, t.withCharmActions, result)
} else if t.expectNoResults {
c.Check(string(result), gc.Matches, t.expectMessage+"(?sm).*")
} else {
checkSimpleSchema(c, t.withCharmActions, result)
}
}
}
}()

}()
}
}
}

Expand Down
112 changes: 58 additions & 54 deletions cmd/juju/action/do_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,21 @@ func (s *DoSuite) TestInit(c *gc.C) {
}}

for i, t := range tests {
wrappedCommand, command := action.NewDoCommand()
c.Logf("test %d: should %s:\n$ juju actions do %s\n", i,
t.should, strings.Join(t.args, " "))
args := append([]string{"-e", "dummyenv"}, t.args...)
err := testing.InitCommand(wrappedCommand, args)
if t.expectError == "" {
c.Check(command.UnitTag(), gc.Equals, t.expectUnit)
c.Check(command.ActionName(), gc.Equals, t.expectAction)
c.Check(command.ParamsYAML().Path, gc.Equals, t.expectParamsYamlPath)
c.Check(command.Args(), jc.DeepEquals, t.expectKVArgs)
c.Check(command.ParseStrings(), gc.Equals, t.expectParseStrings)
} else {
c.Check(err, gc.ErrorMatches, t.expectError)
for _, modelFlag := range s.modelFlags {
wrappedCommand, command := action.NewDoCommand()
c.Logf("test %d: should %s:\n$ juju actions do %s\n", i,
t.should, strings.Join(t.args, " "))
args := append([]string{modelFlag, "dummyenv"}, t.args...)
err := testing.InitCommand(wrappedCommand, args)
if t.expectError == "" {
c.Check(command.UnitTag(), gc.Equals, t.expectUnit)
c.Check(command.ActionName(), gc.Equals, t.expectAction)
c.Check(command.ParamsYAML().Path, gc.Equals, t.expectParamsYamlPath)
c.Check(command.Args(), jc.DeepEquals, t.expectKVArgs)
c.Check(command.ParseStrings(), gc.Equals, t.expectParseStrings)
} else {
c.Check(err, gc.ErrorMatches, t.expectError)
}
}
}
}
Expand Down Expand Up @@ -355,48 +357,50 @@ func (s *DoSuite) TestRun(c *gc.C) {
}}

for i, t := range tests {
func() {
c.Logf("test %d: should %s:\n$ juju actions do %s\n", i,
t.should, strings.Join(t.withArgs, " "))
fakeClient := &fakeAPIClient{
actionResults: t.withActionResults,
}
if t.withAPIErr != "" {
fakeClient.apiErr = errors.New(t.withAPIErr)
}
restore := s.patchAPIClient(fakeClient)
defer restore()
for _, modelFlag := range s.modelFlags {
func() {
c.Logf("test %d: should %s:\n$ juju actions do %s\n", i,
t.should, strings.Join(t.withArgs, " "))
fakeClient := &fakeAPIClient{
actionResults: t.withActionResults,
}
if t.withAPIErr != "" {
fakeClient.apiErr = errors.New(t.withAPIErr)
}
restore := s.patchAPIClient(fakeClient)
defer restore()

wrappedCommand, _ := action.NewDoCommand()
args := append([]string{"-e", "dummyenv"}, t.withArgs...)
ctx, err := testing.RunCommand(c, wrappedCommand, args...)
wrappedCommand, _ := action.NewDoCommand()
args := append([]string{modelFlag, "dummyenv"}, t.withArgs...)
ctx, err := testing.RunCommand(c, wrappedCommand, args...)

if t.expectedErr != "" || t.withAPIErr != "" {
c.Check(err, gc.ErrorMatches, t.expectedErr)
} else {
c.Assert(err, gc.IsNil)
// Before comparing, double-check to avoid
// panics in malformed tests.
c.Assert(len(t.withActionResults), gc.Equals, 1)
// Make sure the test's expected Action was
// non-nil and correct.
c.Assert(t.withActionResults[0].Action, gc.NotNil)
expectedTag, err := names.ParseActionTag(t.withActionResults[0].Action.Tag)
c.Assert(err, gc.IsNil)
// Make sure the CLI responded with the expected tag
keyToCheck := "Action queued with id"
expectedMap := map[string]string{keyToCheck: expectedTag.Id()}
outputResult := ctx.Stdout.(*bytes.Buffer).Bytes()
resultMap := make(map[string]string)
err = yaml.Unmarshal(outputResult, &resultMap)
c.Assert(err, gc.IsNil)
c.Check(resultMap, jc.DeepEquals, expectedMap)
// Make sure the Action sent to the API to be
// enqueued was indeed the expected map
enqueued := fakeClient.EnqueuedActions()
c.Assert(enqueued.Actions, gc.HasLen, 1)
c.Check(enqueued.Actions[0], jc.DeepEquals, t.expectedActionEnqueued)
}
}()
if t.expectedErr != "" || t.withAPIErr != "" {
c.Check(err, gc.ErrorMatches, t.expectedErr)
} else {
c.Assert(err, gc.IsNil)
// Before comparing, double-check to avoid
// panics in malformed tests.
c.Assert(len(t.withActionResults), gc.Equals, 1)
// Make sure the test's expected Action was
// non-nil and correct.
c.Assert(t.withActionResults[0].Action, gc.NotNil)
expectedTag, err := names.ParseActionTag(t.withActionResults[0].Action.Tag)
c.Assert(err, gc.IsNil)
// Make sure the CLI responded with the expected tag
keyToCheck := "Action queued with id"
expectedMap := map[string]string{keyToCheck: expectedTag.Id()}
outputResult := ctx.Stdout.(*bytes.Buffer).Bytes()
resultMap := make(map[string]string)
err = yaml.Unmarshal(outputResult, &resultMap)
c.Assert(err, gc.IsNil)
c.Check(resultMap, jc.DeepEquals, expectedMap)
// Make sure the Action sent to the API to be
// enqueued was indeed the expected map
enqueued := fakeClient.EnqueuedActions()
c.Assert(enqueued.Actions, gc.HasLen, 1)
c.Check(enqueued.Actions[0], jc.DeepEquals, t.expectedActionEnqueued)
}
}()
}
}
}
54 changes: 29 additions & 25 deletions cmd/juju/action/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ func (s *FetchSuite) TestInit(c *gc.C) {
}}

for i, t := range tests {
c.Logf("test %d: it should %s: juju actions fetch %s", i,
t.should, strings.Join(t.args, " "))
cmd := action.NewFetchCommand()
args := append([]string{"-e", "dummyenv"}, t.args...)
err := testing.InitCommand(cmd, args)
if t.expectError != "" {
c.Check(err, gc.ErrorMatches, t.expectError)
for _, modelFlag := range s.modelFlags {
c.Logf("test %d: it should %s: juju actions fetch %s", i,
t.should, strings.Join(t.args, " "))
cmd := action.NewFetchCommand()
args := append([]string{modelFlag, "dummyenv"}, t.args...)
err := testing.InitCommand(cmd, args)
if t.expectError != "" {
c.Check(err, gc.ErrorMatches, t.expectError)
}
}
}
}
Expand Down Expand Up @@ -272,30 +274,32 @@ timing:
}}

for i, t := range tests {
c.Logf("test %d: should %s", i, t.should)
testRunHelper(
c, s,
makeFakeClient(
t.withAPIDelay,
t.withAPITimeout,
t.withTags,
t.withAPIResponse,
t.withAPIError),
t.expectedErr,
t.expectedOutput,
t.withClientWait,
t.withClientQueryID,
)
for _, modelFlag := range s.modelFlags {
c.Logf("test %d (model flag %v): should %s", i, modelFlag, t.should)
testRunHelper(
c, s,
makeFakeClient(
t.withAPIDelay,
t.withAPITimeout,
t.withTags,
t.withAPIResponse,
t.withAPIError),
t.expectedErr,
t.expectedOutput,
t.withClientWait,
t.withClientQueryID,
modelFlag,
)
}
}
}

func testRunHelper(c *gc.C, s *FetchSuite, client *fakeAPIClient, expectedErr, expectedOutput, wait, query string) {
func testRunHelper(c *gc.C, s *FetchSuite, client *fakeAPIClient, expectedErr, expectedOutput, wait, query, modelFlag string) {
unpatch := s.BaseActionSuite.patchAPIClient(client)
defer unpatch()
args := append([]string{"-e", "dummyenv"}, []string{query}...)
args := append([]string{modelFlag, "dummyenv"}, query)
if wait != "" {
args = append(args, "--wait")
args = append(args, wait)
args = append(args, "--wait", wait)
}
cmd := action.NewFetchCommand()
ctx, err := testing.RunCommand(c, cmd, args...)
Expand Down
Loading

0 comments on commit 251c905

Please sign in to comment.