~dave-cheney/juju-core/102-cmd-init-context

« back to all changes in this revision

Viewing changes to cmd/juju/cmd_test.go

  • Committer: Dave Cheney
  • Date: 2012-09-17 15:23:08 UTC
  • mfrom: (507.1.7 096-cmd-config-var)
  • Revision ID: david.cheney@canonical.com-20120917152308-vlt0nvcq4gwl6oj2
cmd: add FileVar flag and use it

PyJuJu had a nice construct that allowed a flag that was a file, or more
specifically the contents of a file to be handled nicely. As deploy ended
up implementing this, and I need it now for juju set, it made sense to 
pretty it up.

R=niemeyer
CC=
https://codereview.appspot.com/6490121

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package main
2
2
 
3
3
import (
 
4
        "net/http"
 
5
        "os"
 
6
        "path/filepath"
 
7
        "reflect"
 
8
 
4
9
        "launchpad.net/gnuflag"
5
10
        . "launchpad.net/gocheck"
6
11
        "launchpad.net/juju-core/cmd"
8
13
        "launchpad.net/juju-core/environs/dummy"
9
14
        "launchpad.net/juju-core/juju/testing"
10
15
        "launchpad.net/juju-core/version"
11
 
        "net/http"
12
 
        "os"
13
 
        "reflect"
14
16
)
15
17
 
16
18
type CmdSuite struct {
182
184
                []string{"charm-name", "service-name"},
183
185
                &DeployCommand{ServiceName: "service-name"},
184
186
        }, {
185
 
                []string{"--config", "/path/to/config.yaml", "charm-name"},
186
 
                &DeployCommand{ConfPath: "/path/to/config.yaml"},
187
 
        }, {
188
187
                []string{"--repository", "/path/to/another-repo", "charm-name"},
189
188
                &DeployCommand{RepoPath: "/path/to/another-repo"},
190
189
        }, {
230
229
                c.Assert(com, DeepEquals, t.com)
231
230
        }
232
231
 
 
232
        // test --config path
 
233
        dir := c.MkDir()
 
234
        path := filepath.Join(dir, "testconfig.yaml")
 
235
        file, err := os.Create(path)
 
236
        c.Assert(err, IsNil)
 
237
        file.Close()
 
238
        com, err := initDeployCommand("--config", path, "charm-name")
 
239
        c.Assert(err, IsNil)
 
240
        defer com.Config.Close()
 
241
        c.Assert(com.Config.Path, Equals, path)
 
242
        c.Assert(com.Config.ReadCloser, NotNil)
 
243
 
233
244
        // missing args
234
 
        _, err := initDeployCommand()
 
245
        _, err = initDeployCommand()
235
246
        c.Assert(err, ErrorMatches, "no charm specified")
236
247
 
237
248
        // bad unit count