Пример #1
0
func (s *ConfigCommandSuite) TestInit(c *gc.C) {
	for i, test := range []struct {
		args       []string
		errorMatch string
		nilErr     bool
	}{
		{ // Test set
			// 0
			args:       []string{"special=extra", "special=other"},
			errorMatch: `key "special" specified more than once`,
		}, {
			// 1
			args:       []string{"agent-version=2.0.0"},
			errorMatch: `agent-version must be set via "upgrade-juju"`,
		}, {
			// Test reset
			// 2
			args:       []string{"--reset"},
			errorMatch: "no keys specified",
		}, {
			// 3
			args:   []string{"--reset", "something", "weird"},
			nilErr: true,
		}, {
			// 4
			args:       []string{"--reset", "agent-version"},
			errorMatch: "agent-version cannot be reset",
		}, {
			// Test get
			// 5
			args:   nil,
			nilErr: true,
		}, {
			// 6
			args:   []string{"one"},
			nilErr: true,
		}, {
			// 7
			args:       []string{"one", "two"},
			errorMatch: "can only retrieve a single value, or all values",
		},
	} {
		c.Logf("test %d", i)
		cmd := model.NewConfigCommandForTest(s.fake)
		err := testing.InitCommand(cmd, test.args)
		if test.nilErr {
			c.Check(err, jc.ErrorIsNil)
			continue
		}
		c.Check(err, gc.ErrorMatches, test.errorMatch)
	}
}
Пример #2
0
func (s *ConfigCommandSuite) TestInit(c *gc.C) {
	for i, test := range []struct {
		desc       string
		args       []string
		errorMatch string
		nilErr     bool
	}{
		{ // Test set
			desc:       "keys cannot be duplicates",
			args:       []string{"special=extra", "special=other"},
			errorMatch: `key "special" specified more than once`,
		}, {
			desc:       "agent-version cannot be set",
			args:       []string{"agent-version=2.0.0"},
			errorMatch: `agent-version must be set via "upgrade-juju"`,
		}, {
			// Test reset
			desc:       "reset requires arg",
			args:       []string{"--reset"},
			errorMatch: "flag needs an argument: --reset",
		}, {
			desc:       "cannot set and retrieve at the same time",
			args:       []string{"--reset", "something", "weird"},
			errorMatch: "cannot set and retrieve model values simultaneously",
		}, {
			desc:       "agent-version cannot be reset",
			args:       []string{"--reset", "agent-version"},
			errorMatch: `"agent-version" cannot be reset`,
		}, {
			desc:       "set and reset cannot have duplicate keys",
			args:       []string{"--reset", "special", "special=extra"},
			errorMatch: `key "special" cannot be both set and reset in the same command`,
		}, {
			desc:       "reset cannot have k=v pairs",
			args:       []string{"--reset", "a,b,c=d,e"},
			errorMatch: `--reset accepts a comma delimited set of keys "a,b,c", received: "c=d"`,
		}, {
			// Test get
			desc:   "get all succeds",
			args:   nil,
			nilErr: true,
		}, {
			desc:   "get one succeeds",
			args:   []string{"one"},
			nilErr: true,
		}, {
			desc:       "get multiple fails",
			args:       []string{"one", "two"},
			errorMatch: "can only retrieve a single value, or all values",
		}, {
			// test variations
			desc:   "test reset interspersed",
			args:   []string{"--reset", "one", "special=foo", "--reset", "two"},
			nilErr: true,
		},
	} {
		c.Logf("test %d: %s", i, test.desc)
		cmd := model.NewConfigCommandForTest(s.fake)
		err := testing.InitCommand(cmd, test.args)
		if test.nilErr {
			c.Check(err, jc.ErrorIsNil)
			continue
		}
		c.Check(err, gc.ErrorMatches, test.errorMatch)
	}
}
Пример #3
0
func (s *ConfigCommandSuite) run(c *gc.C, args ...string) (*cmd.Context, error) {
	command := model.NewConfigCommandForTest(s.fake)
	return testing.RunCommand(c, command, args...)
}