Ejemplo n.º 1
0
func (s *SetSuite) assertSetWarning(c *gc.C, dir string, args []string, w string) {
	ctx := coretesting.ContextForDir(c, dir)
	code := cmd.Main(service.NewSetCommandWithAPI(s.fakeClientAPI, 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+".*")
}
Ejemplo n.º 2
0
func (s *SetSuite) TestSetCommandInit(c *gc.C) {
	// missing args
	err := coretesting.InitCommand(service.NewSetCommandWithAPI(s.fakeClientAPI, s.fakeServiceAPI), []string{})
	c.Assert(err, gc.ErrorMatches, "no service name specified")

	// missing service name
	err = coretesting.InitCommand(service.NewSetCommandWithAPI(s.fakeClientAPI, s.fakeServiceAPI), []string{"name=foo"})
	c.Assert(err, gc.ErrorMatches, "no service name specified")

	// --config path, but no service
	err = coretesting.InitCommand(service.NewSetCommandWithAPI(s.fakeClientAPI, s.fakeServiceAPI), []string{"--config", "testconfig.yaml"})
	c.Assert(err, gc.ErrorMatches, "no service name specified")

	// --config and options specified
	err = coretesting.InitCommand(service.NewSetCommandWithAPI(s.fakeClientAPI, s.fakeServiceAPI), []string{"service", "--config", "testconfig.yaml", "bees="})
	c.Assert(err, gc.ErrorMatches, "cannot specify --config when using key=value arguments")
}
Ejemplo n.º 3
0
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.NewSetCommandWithAPI(s.fakeClientAPI, 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.*")
}
Ejemplo n.º 4
0
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.NewSetCommandWithAPI(s.fakeClientAPI, s.fakeServiceAPI), ctx, []string{
		"dummy-service",
		"--config",
		"testconfig.yaml"})

	c.Check(code, gc.Equals, 0)
	c.Check(s.fakeServiceAPI.config, gc.Equals, yamlConfigValue)
}
Ejemplo n.º 5
0
// 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.NewSetCommandWithAPI(s.fakeClientAPI, 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)
}
Ejemplo n.º 6
0
// 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.NewSetCommandWithAPI(s.fakeClientAPI, s.fakeServiceAPI), ctx, append([]string{"dummy-service"}, args...))
	c.Check(code, gc.Equals, 0)
	c.Assert(s.fakeClientAPI.values, gc.DeepEquals, expect)
}