Esempio n. 1
0
func setupConfigfile(c *C, dir string) string {
	ctx := coretesting.ContextForDir(c, dir)
	path := ctx.AbsPath("testconfig.yaml")
	content := []byte("dummy-service:\n  skill-level: 9000\n  username: admin001\n\n")
	err := ioutil.WriteFile(path, content, 0666)
	c.Assert(err, IsNil)
	return path
}
Esempio n. 2
0
func (s *ConfigSuite) TestSetConfig(c *C) {
	sch := s.AddTestingCharm(c, "dummy")
	svc, err := s.State.AddService("dummy-service", sch)
	c.Assert(err, IsNil)
	dir := c.MkDir()
	setupConfigfile(c, dir)
	for i, t := range setTests {
		args := append([]string{"dummy-service"}, t.args...)
		c.Logf("test %d. %s", i, t.about)
		ctx := coretesting.ContextForDir(c, dir)
		code := cmd.Main(&SetCommand{}, ctx, args)
		if t.err != "" {
			c.Check(code, Not(Equals), 0)
			c.Assert(ctx.Stderr.(*bytes.Buffer).String(), Matches, t.err)
		} else {
			c.Check(code, Equals, 0)
			settings, err := svc.ConfigSettings()
			c.Assert(err, IsNil)
			c.Assert(settings, DeepEquals, t.expect)
		}
	}
}