func (s *SetSuite) assertSetWarning(c *gc.C, dir string, args []string, w string) { ctx := coretesting.ContextForDir(c, dir) code := cmd.Main(service.NewSetCommandForTest(s.fakeServiceAPI), ctx, append([]string{"dummy-service"}, args...)) c.Check(code, gc.Equals, 0) c.Assert(strings.Replace(c.GetTestLog(), "\n", " ", -1), gc.Matches, ".*WARNING.*"+w+".*") }
func (s *SetSuite) TestSetCommandInit(c *gc.C) { // missing args err := coretesting.InitCommand(service.NewSetCommandForTest(s.fakeServiceAPI), []string{}) c.Assert(err, gc.ErrorMatches, "no service name specified") // missing service name err = coretesting.InitCommand(service.NewSetCommandForTest(s.fakeServiceAPI), []string{"name=foo"}) c.Assert(err, gc.ErrorMatches, "no service name specified") // --config path, but no service err = coretesting.InitCommand(service.NewSetCommandForTest(s.fakeServiceAPI), []string{"--config", "testconfig.yaml"}) c.Assert(err, gc.ErrorMatches, "no service name specified") // --config and options specified err = coretesting.InitCommand(service.NewSetCommandForTest(s.fakeServiceAPI), []string{"service", "--config", "testconfig.yaml", "bees="}) c.Assert(err, gc.ErrorMatches, "cannot specify --config when using key=value arguments") }
func (s *SetSuite) TestBlockSetConfig(c *gc.C) { // Block operation s.fakeServiceAPI.err = common.OperationBlockedError("TestBlockSetConfig") ctx := coretesting.ContextForDir(c, s.dir) code := cmd.Main(service.NewSetCommandForTest(s.fakeServiceAPI), ctx, []string{ "dummy-service", "--config", "testconfig.yaml"}) c.Check(code, gc.Equals, 1) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestBlockSetConfig.*") }
func (s *SetSuite) TestSetConfig(c *gc.C) { s.assertSetFail(c, s.dir, []string{ "--config", "missing.yaml", }, "error.* "+utils.NoSuchFileErrRegexp+"\n") ctx := coretesting.ContextForDir(c, s.dir) code := cmd.Main(service.NewSetCommandForTest(s.fakeServiceAPI), ctx, []string{ "dummy-service", "--config", "testconfig.yaml"}) c.Check(code, gc.Equals, 0) c.Check(s.fakeServiceAPI.config, gc.Equals, yamlConfigValue) }
// assertSetFail sets configuration options and checks the expected error. func (s *SetSuite) assertSetFail(c *gc.C, dir string, args []string, err string) { ctx := coretesting.ContextForDir(c, dir) code := cmd.Main(service.NewSetCommandForTest(s.fakeServiceAPI), ctx, append([]string{"dummy-service"}, args...)) c.Check(code, gc.Not(gc.Equals), 0) c.Assert(ctx.Stderr.(*bytes.Buffer).String(), gc.Matches, err) }
// assertSetSuccess sets configuration options and checks the expected settings. func (s *SetSuite) assertSetSuccess(c *gc.C, dir string, args []string, expect map[string]interface{}) { ctx := coretesting.ContextForDir(c, dir) code := cmd.Main(service.NewSetCommandForTest(s.fakeServiceAPI), ctx, append([]string{"dummy-service"}, args...)) c.Assert(code, gc.Equals, 0) }