Skip to content

Commit 9442044

Browse files
committed
Corrected the help for exportbundle command
Fixed the format issue Fixed unit test & removed the .yaml Fixed the extra '|' character o/p in stdout Addressed review comments Updated the client facade error message REsolved conflict Removed version from client facade err message Fixed conflicts and so feature test
1 parent 3ebdcbb commit 9442044

File tree

5 files changed

+44
-45
lines changed

5 files changed

+44
-45
lines changed

api/bundle/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewClient(st base.APICallCloser) *Client {
3434
func (c *Client) ExportBundle() (string, error) {
3535
var result params.StringResult
3636
if bestVer := c.BestAPIVersion(); bestVer < 2 {
37-
return "", errors.Errorf("ExportBundle() on v%d is not supported", bestVer)
37+
return "", errors.Errorf("this controller version does not support bundle export feature.")
3838
}
3939

4040
if err := c.facade.FacadeCall("ExportBundle", nil, &result); err != nil {

api/bundle/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (s *bundleMockSuite) TestFailExportBundlev1(c *gc.C) {
4646
)
4747
result, err := client.ExportBundle()
4848
c.Assert(err, gc.NotNil)
49-
c.Assert(err.Error(), gc.Equals, "ExportBundle() on v1 is not supported")
49+
c.Assert(err.Error(), gc.Equals, "this controller version does not support bundle export feature.")
5050
c.Assert(result, jc.DeepEquals, "")
5151
}
5252

cmd/juju/model/exportbundle.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"github.com/juju/juju/api/bundle"
1414
"github.com/juju/juju/cmd/modelcmd"
15-
"github.com/juju/juju/cmd/output"
1615
)
1716

1817
// NewExportBundleCommand returns a fully constructed export bundle command.
@@ -32,30 +31,30 @@ type exportBundleCommand struct {
3231
}
3332

3433
const exportBundleHelpDoc = `
35-
Exports the current model configuration as bundle.
34+
Exports the current model configuration as a reusable bundle.
3635
3736
If --filename is not used, the configuration is printed to stdout.
3837
--filename specifies an output file.
3938
4039
Examples:
4140
4241
juju export-bundle
43-
juju export-bundle --filename mymodel
42+
juju export-bundle --filename mymodel.yaml
43+
4444
`
4545

4646
// Info implements Command.
4747
func (c *exportBundleCommand) Info() *cmd.Info {
4848
return &cmd.Info{
4949
Name: "export-bundle",
50-
Purpose: "Exports the current model configuration as bundle.",
50+
Purpose: "Exports the current model configuration as a reusable bundle.",
5151
Doc: exportBundleHelpDoc,
5252
}
5353
}
5454

5555
// SetFlags implements Command.
5656
func (c *exportBundleCommand) SetFlags(f *gnuflag.FlagSet) {
5757
c.ModelCommandBase.SetFlags(f)
58-
c.out.AddFlags(f, "yaml", output.DefaultFormatters)
5958
f.StringVar(&c.Filename, "filename", "", "Bundle file")
6059
}
6160

@@ -93,9 +92,10 @@ func (c *exportBundleCommand) Run(ctx *cmd.Context) error {
9392
}
9493

9594
if c.Filename == "" {
96-
return c.out.Write(ctx, result)
95+
_, err := fmt.Fprintf(ctx.Stdout, "%v", result)
96+
return err
9797
}
98-
filename := c.Filename + ".yaml"
98+
filename := c.Filename
9999
file, err := os.Create(filename)
100100
if err != nil {
101101
return errors.Annotate(err, "while creating local file")

cmd/juju/model/exportbundle_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,26 @@ func (s *ExportBundleCommandSuite) TestExportBundleSuccessNoFilename(c *gc.C) {
8686
})
8787

8888
out := cmdtesting.Stdout(ctx)
89-
c.Assert(out, gc.Equals, "|\n"+
90-
" applications:\n"+
91-
" mysql:\n"+
92-
" charm: \"\"\n"+
93-
" num_units: 1\n"+
94-
" to:\n"+
95-
" - \"0\"\n"+
96-
" wordpress:\n"+
97-
" charm: \"\"\n"+
98-
" num_units: 2\n"+
99-
" to:\n"+
100-
" - \"0\"\n"+
101-
" - \"1\"\n"+
102-
" machines:\n"+
103-
" \"0\": {}\n"+
104-
" \"1\": {}\n"+
105-
" series: xenial\n"+
106-
" relations:\n"+
107-
" - - wordpress:db\n"+
108-
" - mysql:mysql\n")
89+
c.Assert(out, gc.Equals, ""+
90+
"applications:\n"+
91+
" mysql:\n"+
92+
" charm: \"\"\n"+
93+
" num_units: 1\n"+
94+
" to:\n"+
95+
" - \"0\"\n"+
96+
" wordpress:\n"+
97+
" charm: \"\"\n"+
98+
" num_units: 2\n"+
99+
" to:\n"+
100+
" - \"0\"\n"+
101+
" - \"1\"\n"+
102+
"machines:\n"+
103+
" \"0\": {}\n"+
104+
" \"1\": {}\n"+
105+
"series: xenial\n"+
106+
"relations:\n"+
107+
"- - wordpress:db\n"+
108+
" - mysql:mysql\n")
109109
}
110110

111111
func (s *ExportBundleCommandSuite) TestExportBundleSuccessFilename(c *gc.C) {
@@ -129,8 +129,8 @@ func (s *ExportBundleCommandSuite) TestExportBundleSuccessFilename(c *gc.C) {
129129
})
130130

131131
out := cmdtesting.Stdout(ctx)
132-
c.Assert(out, gc.Equals, "Bundle successfully exported to mymodel.yaml\n")
133-
output, err := ioutil.ReadFile("mymodel.yaml")
132+
c.Assert(out, gc.Equals, "Bundle successfully exported to mymodel\n")
133+
output, err := ioutil.ReadFile("mymodel")
134134
c.Check(err, jc.ErrorIsNil)
135135
c.Assert(string(output), gc.Equals, "applications:\n"+
136136
" magic:\n"+
@@ -163,8 +163,8 @@ func (s *ExportBundleCommandSuite) TestExportBundleSuccesssOverwriteFilename(c *
163163
})
164164

165165
out := cmdtesting.Stdout(ctx)
166-
c.Assert(out, gc.Equals, "Bundle successfully exported to mymodel.yaml\n")
167-
output, err := ioutil.ReadFile("mymodel.yaml")
166+
c.Assert(out, gc.Equals, "Bundle successfully exported to mymodel\n")
167+
output, err := ioutil.ReadFile("mymodel")
168168
c.Check(err, jc.ErrorIsNil)
169169
c.Assert(string(output), gc.Equals, "fake-data")
170170
}

featuretests/cmd_juju_bundle_test.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,15 @@ func (s *CmdExportBundleSuite) TestExportBundle(c *gc.C) {
6565
c.Assert(err, jc.ErrorIsNil)
6666
output := cmdtesting.Stdout(ctx)
6767
c.Assert(output, gc.Equals, ""+
68-
"|\n"+
69-
" applications:\n"+
70-
" logging:\n"+
71-
" charm: cs:quantal/logging-43\n"+
72-
" wordpress:\n"+
73-
" charm: cs:quantal/wordpress-23\n"+
74-
" series: bionic\n"+
75-
" relations:\n"+
76-
" - - wordpress:juju-info\n"+
77-
" - logging:info\n"+
78-
" - - wordpress:logging-dir\n"+
79-
" - logging:logging-directory\n")
68+
"applications:\n"+
69+
" logging:\n"+
70+
" charm: cs:quantal/logging-43\n"+
71+
" wordpress:\n"+
72+
" charm: cs:quantal/wordpress-23\n"+
73+
"series: bionic\n"+
74+
"relations:\n"+
75+
"- - wordpress:juju-info\n"+
76+
" - logging:info\n"+
77+
"- - wordpress:logging-dir\n"+
78+
" - logging:logging-directory\n")
8079
}

0 commit comments

Comments
 (0)