コード例 #1
0
ファイル: defined_test.go プロジェクト: AlexisBruemmer/juju
func (s *DefinedSuite) TestInit(c *gc.C) {
	tests := []struct {
		should               string
		args                 []string
		expectedSvc          names.ServiceTag
		expectedOutputSchema bool
		expectedErr          string
	}{{
		should:      "fail with missing service name",
		args:        []string{},
		expectedErr: "no service name specified",
	}, {
		should:      "fail with invalid service name",
		args:        []string{invalidServiceId},
		expectedErr: "invalid service name \"" + invalidServiceId + "\"",
	}, {
		should:      "fail with too many args",
		args:        []string{"two", "things"},
		expectedErr: "unrecognized args: \\[\"things\"\\]",
	}, {
		should:      "init properly with valid service name",
		args:        []string{validServiceId},
		expectedSvc: names.NewServiceTag(validServiceId),
	}, {
		should:               "init properly with valid service name and --schema",
		args:                 []string{"--schema", validServiceId},
		expectedOutputSchema: true,
		expectedSvc:          names.NewServiceTag(validServiceId),
	}}

	for i, t := range tests {
		for _, modelFlag := range s.modelFlags {
			c.Logf("test %d should %s: juju actions defined %s", i,
				t.should, strings.Join(t.args, " "))
			s.wrappedCommand, s.command = action.NewDefinedCommand(s.store)
			args := append([]string{modelFlag, "admin"}, t.args...)
			err := testing.InitCommand(s.wrappedCommand, args)
			if t.expectedErr == "" {
				c.Check(s.command.ServiceTag(), gc.Equals, t.expectedSvc)
				c.Check(s.command.FullSchema(), gc.Equals, t.expectedOutputSchema)
			} else {
				c.Check(err, gc.ErrorMatches, t.expectedErr)
			}
		}
	}
}
コード例 #2
0
ファイル: defined_test.go プロジェクト: imoapps/juju
func (s *DefinedSuite) TestRun(c *gc.C) {
	tests := []struct {
		should           string
		expectFullSchema bool
		expectNoResults  bool
		expectMessage    string
		withArgs         []string
		withAPIErr       string
		withCharmActions *charm.Actions
		expectedErr      string
	}{{
		should:      "pass back API error correctly",
		withArgs:    []string{validServiceId},
		withAPIErr:  "an API error",
		expectedErr: "an API error",
	}, {
		should:           "get short results properly",
		withArgs:         []string{validServiceId},
		withCharmActions: someCharmActions,
	}, {
		should:           "get full schema results properly",
		withArgs:         []string{"--schema", validServiceId},
		expectFullSchema: true,
		withCharmActions: someCharmActions,
	}, {
		should:           "work properly when no results found",
		withArgs:         []string{validServiceId},
		expectNoResults:  true,
		expectMessage:    "No actions defined for " + validServiceId,
		withCharmActions: &charm.Actions{ActionSpecs: map[string]charm.ActionSpec{}},
	}}

	for i, t := range tests {
		func() {
			c.Logf("test %d should %s", i, t.should)

			fakeClient := &fakeAPIClient{charmActions: t.withCharmActions}
			if t.withAPIErr != "" {
				fakeClient.apiErr = errors.New(t.withAPIErr)
			}
			restore := s.patchAPIClient(fakeClient)
			defer restore()

			args := append([]string{"-e", "dummyenv"}, t.withArgs...)
			s.wrappedCommand, s.command = action.NewDefinedCommand()
			ctx, err := testing.RunCommand(c, s.wrappedCommand, args...)

			if t.expectedErr != "" || t.withAPIErr != "" {
				c.Check(err, gc.ErrorMatches, t.expectedErr)
			} else {
				c.Assert(err, gc.IsNil)
				result := ctx.Stdout.(*bytes.Buffer).Bytes()
				if t.expectFullSchema {
					checkFullSchema(c, t.withCharmActions, result)
				} else if t.expectNoResults {
					c.Check(string(result), gc.Matches, t.expectMessage+"(?sm).*")
				} else {
					checkSimpleSchema(c, t.withCharmActions, result)
				}
			}
		}()
	}
}
コード例 #3
0
ファイル: defined_test.go プロジェクト: imoapps/juju
func (s *DefinedSuite) SetUpTest(c *gc.C) {
	s.BaseActionSuite.SetUpTest(c)
	s.wrappedCommand, s.command = action.NewDefinedCommand()
}