Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(172)

Side by Side Diff: cmd/juju/main_test.go

Issue 13642045: Always show cmd errors/warnings (Closed)
Patch Set: Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « [revision details] ('k') | cmd/juju/plugin_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package main 4 package main
5 5
6 import ( 6 import (
7 "bytes" 7 "bytes"
8 "flag" 8 "flag"
9 "fmt" 9 "fmt"
10 "io/ioutil" 10 "io/ioutil"
11 "os" 11 "os"
12 "os/exec" 12 "os/exec"
13 "path/filepath" 13 "path/filepath"
14 "strings" 14 "strings"
15 stdtesting "testing" 15 stdtesting "testing"
16 16
17 "launchpad.net/gnuflag" 17 "launchpad.net/gnuflag"
18 gc "launchpad.net/gocheck" 18 gc "launchpad.net/gocheck"
19 "launchpad.net/loggo" 19 "launchpad.net/loggo"
20 20
21 "launchpad.net/juju-core/cmd" 21 "launchpad.net/juju-core/cmd"
22 "launchpad.net/juju-core/environs/config" 22 "launchpad.net/juju-core/environs/config"
23 "launchpad.net/juju-core/juju/osenv" 23 "launchpad.net/juju-core/juju/osenv"
24 _ "launchpad.net/juju-core/provider/dummy" 24 _ "launchpad.net/juju-core/provider/dummy"
25 "launchpad.net/juju-core/testing" 25 "launchpad.net/juju-core/testing"
26 jc "launchpad.net/juju-core/testing/checkers"
26 "launchpad.net/juju-core/version" 27 "launchpad.net/juju-core/version"
27 ) 28 )
28 29
29 func TestPackage(t *stdtesting.T) { 30 func TestPackage(t *stdtesting.T) {
30 testing.MgoTestPackage(t) 31 testing.MgoTestPackage(t)
31 } 32 }
32 33
33 type MainSuite struct{} 34 type MainSuite struct{}
34 35
35 var _ = gc.Suite(&MainSuite{}) 36 var _ = gc.Suite(&MainSuite{})
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 out: strings.TrimLeft(helpBasics, "\n"), 110 out: strings.TrimLeft(helpBasics, "\n"),
110 }, { 111 }, {
111 summary: "juju help basics is the same as juju", 112 summary: "juju help basics is the same as juju",
112 args: []string{"help", "basics"}, 113 args: []string{"help", "basics"},
113 code: 0, 114 code: 0,
114 out: strings.TrimLeft(helpBasics, "\n"), 115 out: strings.TrimLeft(helpBasics, "\n"),
115 }, { 116 }, {
116 summary: "juju help foo doesn't exist", 117 summary: "juju help foo doesn't exist",
117 args: []string{"help", "foo"}, 118 args: []string{"help", "foo"},
118 code: 1, 119 code: 1,
119 » » out: "error: unknown command or topic for foo\n", 120 » » out: "ERROR unknown command or topic for foo\n",
120 }, { 121 }, {
121 summary: "juju help deploy shows the default help without global options", 122 summary: "juju help deploy shows the default help without global options",
122 args: []string{"help", "deploy"}, 123 args: []string{"help", "deploy"},
123 code: 0, 124 code: 0,
124 out: deployHelpText(), 125 out: deployHelpText(),
125 }, { 126 }, {
126 summary: "juju --help deploy shows the same help as 'help deploy '", 127 summary: "juju --help deploy shows the same help as 'help deploy '",
127 args: []string{"--help", "deploy"}, 128 args: []string{"--help", "deploy"},
128 code: 0, 129 code: 0,
129 out: deployHelpText(), 130 out: deployHelpText(),
130 }, { 131 }, {
131 summary: "juju deploy --help shows the same help as 'help deploy '", 132 summary: "juju deploy --help shows the same help as 'help deploy '",
132 args: []string{"deploy", "--help"}, 133 args: []string{"deploy", "--help"},
133 code: 0, 134 code: 0,
134 out: deployHelpText(), 135 out: deployHelpText(),
135 }, { 136 }, {
136 summary: "unknown command", 137 summary: "unknown command",
137 args: []string{"discombobulate"}, 138 args: []string{"discombobulate"},
138 code: 1, 139 code: 1,
139 » » out: "error: unrecognized command: juju discombobulate\n", 140 » » out: "ERROR unrecognized command: juju discombobulate\n",
140 }, { 141 }, {
141 summary: "unknown option before command", 142 summary: "unknown option before command",
142 args: []string{"--cheese", "bootstrap"}, 143 args: []string{"--cheese", "bootstrap"},
143 code: 2, 144 code: 2,
144 out: "error: flag provided but not defined: --cheese\n", 145 out: "error: flag provided but not defined: --cheese\n",
145 }, { 146 }, {
146 summary: "unknown option after command", 147 summary: "unknown option after command",
147 args: []string{"bootstrap", "--cheese"}, 148 args: []string{"bootstrap", "--cheese"},
148 code: 2, 149 code: 2,
149 out: "error: flag provided but not defined: --cheese\n", 150 out: "error: flag provided but not defined: --cheese\n",
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 c.Assert(err, gc.IsNil) 187 c.Assert(err, gc.IsNil)
187 return fmt.Sprintf("environment configuration has no admin-secret") 188 return fmt.Sprintf("environment configuration has no admin-secret")
188 } 189 }
189 190
190 func (s *MainSuite) TestActualRunJujuArgsBeforeCommand(c *gc.C) { 191 func (s *MainSuite) TestActualRunJujuArgsBeforeCommand(c *gc.C) {
191 defer testing.MakeFakeHomeNoEnvironments(c, "one").Restore() 192 defer testing.MakeFakeHomeNoEnvironments(c, "one").Restore()
192 // Check global args work when specified before command 193 // Check global args work when specified before command
193 msg := breakJuju(c, "Bootstrap") 194 msg := breakJuju(c, "Bootstrap")
194 logpath := filepath.Join(c.MkDir(), "log") 195 logpath := filepath.Join(c.MkDir(), "log")
195 out := badrun(c, 1, "--log-file", logpath, "bootstrap") 196 out := badrun(c, 1, "--log-file", logpath, "bootstrap")
196 » c.Assert(out, gc.Equals, "error: "+msg+"\n") 197 » c.Assert(out, jc.HasSuffix, "ERROR "+msg+"\n")
197 content, err := ioutil.ReadFile(logpath) 198 content, err := ioutil.ReadFile(logpath)
198 c.Assert(err, gc.IsNil) 199 c.Assert(err, gc.IsNil)
199 » fullmsg := fmt.Sprintf(`(.|\n)*ERROR .* command failed: %s\n`, msg) 200 » fullmsg := fmt.Sprintf(`(.|\n)*ERROR .* %s\n`, msg)
200 c.Assert(string(content), gc.Matches, fullmsg) 201 c.Assert(string(content), gc.Matches, fullmsg)
201 } 202 }
202 203
203 func (s *MainSuite) TestActualRunJujuArgsAfterCommand(c *gc.C) { 204 func (s *MainSuite) TestActualRunJujuArgsAfterCommand(c *gc.C) {
204 defer testing.MakeFakeHomeNoEnvironments(c, "one").Restore() 205 defer testing.MakeFakeHomeNoEnvironments(c, "one").Restore()
205 // Check global args work when specified after command 206 // Check global args work when specified after command
206 msg := breakJuju(c, "Bootstrap") 207 msg := breakJuju(c, "Bootstrap")
207 logpath := filepath.Join(c.MkDir(), "log") 208 logpath := filepath.Join(c.MkDir(), "log")
208 out := badrun(c, 1, "bootstrap", "--log-file", logpath) 209 out := badrun(c, 1, "bootstrap", "--log-file", logpath)
209 » c.Assert(out, gc.Equals, "error: "+msg+"\n") 210 » c.Assert(out, jc.HasSuffix, "ERROR "+msg+"\n")
210 content, err := ioutil.ReadFile(logpath) 211 content, err := ioutil.ReadFile(logpath)
211 c.Assert(err, gc.IsNil) 212 c.Assert(err, gc.IsNil)
212 » fullmsg := fmt.Sprintf(`(.|\n)*ERROR .* command failed: %s\n`, msg) 213 » fullmsg := fmt.Sprintf(`(.|\n)*ERROR .* %s\n`, msg)
213 c.Assert(string(content), gc.Matches, fullmsg) 214 c.Assert(string(content), gc.Matches, fullmsg)
214 } 215 }
215 216
216 var commandNames = []string{ 217 var commandNames = []string{
217 "add-machine", 218 "add-machine",
218 "add-relation", 219 "add-relation",
219 "add-unit", 220 "add-unit",
220 "api-endpoints", 221 "api-endpoints",
221 "bootstrap", 222 "bootstrap",
222 "debug-hooks", 223 "debug-hooks",
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 if len(f) == 0 || line[0] != '-' { 334 if len(f) == 0 || line[0] != '-' {
334 continue 335 continue
335 } 336 }
336 flags = append(flags, line) 337 flags = append(flags, line)
337 } 338 }
338 c.Assert(len(flags), gc.Equals, len(globalFlags)) 339 c.Assert(len(flags), gc.Equals, len(globalFlags))
339 for i, line := range flags { 340 for i, line := range flags {
340 c.Assert(line, gc.Matches, globalFlags[i]) 341 c.Assert(line, gc.Matches, globalFlags[i])
341 } 342 }
342 } 343 }
OLDNEW
« no previous file with comments | « [revision details] ('k') | cmd/juju/plugin_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b