~niemeyer/juju-core/old-state

« back to all changes in this revision

Viewing changes to cmd/juju/cmd_test.go

cmd/juju: set: add --config path

Checkpoint branch: Add --config path option. Option value parsing is complicated, and comming up next.

R=fwereade
CC=
https://codereview.appspot.com/6532043

Show diffs side-by-side

added added

removed removed

Lines of Context:
334
334
        c.Assert(err, ErrorMatches, "missing option key")
335
335
 
336
336
        // strange, but correct
337
 
        cmd, err := initSetCommand("dummy", "name = cow")
338
 
        c.Assert(err, IsNil)
339
 
        c.Assert(len(cmd.Options), Equals, 1)
340
 
        c.Assert(cmd.Options[0].Key, Equals, "name")
341
 
        c.Assert(cmd.Options[0].Value, Equals, "cow")
 
337
        sc, err := initSetCommand("dummy", "name = cow")
 
338
        c.Assert(err, IsNil)
 
339
        c.Assert(len(sc.Options), Equals, 1)
 
340
        c.Assert(sc.Options[0].Key, Equals, "name")
 
341
        c.Assert(sc.Options[0].Value, Equals, "cow")
 
342
 
 
343
        // test --config path
 
344
        expected := []byte("this: is some test data")
 
345
        ctx := &cmd.Context{c.MkDir(), nil, nil, nil}
 
346
        path := ctx.AbsPath("testconfig.yaml")
 
347
        file, err := os.Create(path)
 
348
        c.Assert(err, IsNil)
 
349
        _, err = file.Write(expected)
 
350
        c.Assert(err, IsNil)
 
351
        file.Close()
 
352
        com, err := initSetCommand("--config", "testconfig.yaml", "service")
 
353
        c.Assert(err, IsNil)
 
354
        c.Assert(com.Config.Path, Equals, "testconfig.yaml")
 
355
        actual, err := com.Config.Read(ctx)
 
356
        c.Assert(err, IsNil)
 
357
        c.Assert(actual, DeepEquals, expected)
 
358
 
 
359
        // --config path, but no service
 
360
        com, err = initSetCommand("--config", "testconfig")
 
361
        c.Assert(err, ErrorMatches, "no service name specified")
342
362
}