コード例 #1
0
func (s *listAgreementsSuite) TestGetUsersAgreementsWithTermOwner(c *gc.C) {
	ctx, err := cmdtesting.RunCommand(c, listagreements.NewListAgreementsCommand())
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(cmdtesting.Stdout(ctx), gc.Equals, `[]
`)
	c.Assert(s.client.called, jc.IsTrue)

	s.client.setError("well, this is embarassing")
	ctx, err = cmdtesting.RunCommand(c, listagreements.NewListAgreementsCommand())
	c.Assert(err, gc.ErrorMatches, "failed to list user agreements: well, this is embarassing")
	c.Assert(s.client.called, jc.IsTrue)

	agreements := []terms.AgreementResponse{{
		User:      "******",
		Owner:     "owner",
		Term:      "test-term",
		Revision:  1,
		CreatedOn: time.Date(2015, 12, 25, 0, 0, 0, 0, time.UTC),
	}}
	s.client.setAgreements(agreements)

	ctx, err = cmdtesting.RunCommand(c, listagreements.NewListAgreementsCommand())
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ctx, gc.NotNil)
	c.Assert(cmdtesting.Stdout(ctx), gc.Equals, expectedListAgreementsJSONOutputWithOwner)
	c.Assert(s.client.called, jc.IsTrue)

	ctx, err = cmdtesting.RunCommand(c, listagreements.NewListAgreementsCommand(), "--format", "yaml")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ctx, gc.NotNil)
	c.Assert(cmdtesting.Stdout(ctx), gc.Equals, "- user: test-user\n  owner: owner\n  term: test-term\n  revision: 1\n  createdon: 2015-12-25T00:00:00Z\n")
	c.Assert(s.client.called, jc.IsTrue)
}
コード例 #2
0
ファイル: help_test.go プロジェクト: juju/cmd
func (s *HelpCommandSuite) TestMultipleSuperCommands(c *gc.C) {
	level1 := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "level1"})
	level2 := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "level2", UsagePrefix: "level1"})
	level1.Register(level2)
	level3 := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "level3", UsagePrefix: "level1 level2"})
	level2.Register(level3)
	level3.Register(&TestCommand{Name: "blah"})

	ctx, err := cmdtesting.RunCommand(c, level1, "help", "level2", "level3", "blah")
	c.Assert(err, jc.ErrorIsNil)
	s.assertStdOutMatches(c, ctx, "Usage: level1 level2 level3 blah.*blah-doc.*")

	_, err = cmdtesting.RunCommand(c, level1, "help", "level2", "missing", "blah")
	c.Assert(err, gc.ErrorMatches, `subcommand "missing" not found`)
}
コード例 #3
0
ファイル: allocate_test.go プロジェクト: tasdomas/romulus-1
func (s *allocateSuite) TestAllocateErrors(c *gc.C) {
	tests := []struct {
		about         string
		args          []string
		expectedError string
	}{{
		about:         "no args",
		args:          []string{},
		expectedError: "budget and service name required",
	}, {
		about:         "budget without allocation limit",
		args:          []string{"name", "db"},
		expectedError: "invalid budget specification, expecting <budget>:<limit>",
	}, {
		about:         "service not specified",
		args:          []string{"name:100"},
		expectedError: "budget and service name required",
	}}
	for i, test := range tests {
		c.Logf("test %d: %s", i, test.about)
		set := allocate.NewAllocateCommand()
		_, err := cmdtesting.RunCommand(c, set, test.args...)
		c.Check(err, gc.ErrorMatches, test.expectedError)
		s.mockAPI.CheckNoCalls(c)
	}
}
コード例 #4
0
ファイル: allocate_test.go プロジェクト: tasdomas/romulus-1
func (s *allocateSuite) TestallocateAPIError(c *gc.C) {
	s.stub.SetErrors(errors.New("something failed"))
	set := allocate.NewAllocateCommand()
	_, err := cmdtesting.RunCommand(c, set, "name:100", "db")
	c.Assert(err, gc.ErrorMatches, "failed to create allocation: something failed")
	s.mockAPI.CheckCall(c, 0, "CreateAllocation", "name", "100", "env-uuid", []string{"db"})
}
コード例 #5
0
func (s *updateAllocationSuite) TestUpdateAllocationErrors(c *gc.C) {
	tests := []struct {
		about         string
		args          []string
		expectedError string
	}{
		{
			about:         "value needs to be a number",
			args:          []string{"name", "badvalue"},
			expectedError: "value needs to be a whole number",
		},
		{
			about:         "value is missing",
			args:          []string{"name"},
			expectedError: "service and value required",
		},
		{
			about:         "no args",
			args:          []string{},
			expectedError: "service and value required",
		},
	}
	for i, test := range tests {
		s.mockAPI.ResetCalls()
		c.Logf("test %d: %s", i, test.about)
		set := updateallocation.NewUpdateAllocationCommand()
		_, err := cmdtesting.RunCommand(c, set, test.args...)
		c.Check(err, gc.ErrorMatches, test.expectedError)
		s.mockAPI.CheckNoCalls(c)
	}
}
コード例 #6
0
func (s *updateAllocationSuite) TestUpdateAllocationAPIError(c *gc.C) {
	s.stub.SetErrors(errors.New("something failed"))
	set := updateallocation.NewUpdateAllocationCommand()
	_, err := cmdtesting.RunCommand(c, set, "name", "5")
	c.Assert(err, gc.ErrorMatches, "failed to update the allocation: something failed")
	s.mockAPI.CheckCall(c, 0, "UpdateAllocation", "env-uuid", "name", "5")
}
コード例 #7
0
ファイル: setbudget_test.go プロジェクト: bac/juju
func (s *setBudgetSuite) TestSetBudgetAPIError(c *gc.C) {
	s.stub.SetErrors(errors.New("something failed"))
	set := setbudget.NewSetBudgetCommand()
	_, err := cmdtesting.RunCommand(c, set, "name", "5")
	c.Assert(err, gc.ErrorMatches, "failed to set the budget: something failed")
	s.mockAPI.CheckCall(c, 0, "SetBudget", "name", "5")
}
コード例 #8
0
ファイル: setbudget_test.go プロジェクト: bac/juju
func (s *setBudgetSuite) TestSetBudgetErrors(c *gc.C) {
	tests := []struct {
		about         string
		args          []string
		expectedError string
	}{
		{
			about:         "value needs to be a number",
			args:          []string{"name", "badvalue"},
			expectedError: "budget value needs to be a whole number",
		},
		{
			about:         "value is missing",
			args:          []string{"name"},
			expectedError: "name and value required",
		},
		{
			about:         "no args",
			args:          []string{},
			expectedError: "name and value required",
		},
	}
	for i, test := range tests {
		c.Logf("test %d: %s", i, test.about)
		s.stub.SetErrors(errors.New(test.expectedError))
		defer s.mockAPI.ResetCalls()
		set := setbudget.NewSetBudgetCommand()
		_, err := cmdtesting.RunCommand(c, set, test.args...)
		c.Assert(err, gc.ErrorMatches, test.expectedError)
		s.mockAPI.CheckNoCalls(c)
	}
}
コード例 #9
0
func (s *createBudgetSuite) TestCreateBudgetAPIError(c *gc.C) {
	s.mockAPI.SetErrors(errors.New("something failed"))
	createCmd := createbudget.NewCreateBudgetCommand()
	_, err := cmdtesting.RunCommand(c, createCmd, "name", "5")
	c.Assert(err, gc.ErrorMatches, "failed to create the budget: something failed")
	s.mockAPI.CheckCall(c, 0, "CreateBudget", "name", "5")
}
コード例 #10
0
func (s *listBudgetsSuite) TestListBudgetsOutputNoBudgets(c *gc.C) {
	s.mockAPI.result = &budget.ListBudgetsResponse{
		Budgets: budget.BudgetSummaries{},
		Total: budget.BudgetTotals{
			Limit:       "0",
			Allocated:   "0",
			Available:   "0",
			Unallocated: "0",
			Consumed:    "0",
		},
		Credit: "0",
	}
	expected := "" +
		"BUDGET       \tMONTHLY\tALLOCATED\tAVAILABLE\tSPENT\n" +
		"TOTAL        \t      0\t        0\t        0\t    0\n" +
		"             \t       \t         \t         \t     \n" +
		"Credit limit:\t      0\t         \t         \t     \n"

	listBudgets := listbudgets.NewListBudgetsCommand()

	ctx, err := cmdtesting.RunCommand(c, listBudgets)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, expected)
	s.mockAPI.CheckCallNames(c, "ListBudgets")
}
コード例 #11
0
func (s *createBudgetSuite) TestCreateBudgetErrors(c *gc.C) {
	tests := []struct {
		about         string
		args          []string
		expectedError string
	}{
		{
			about:         "test value needs to be a number",
			args:          []string{"name", "badvalue"},
			expectedError: "budget value needs to be a whole number",
		},
		{
			about:         "value is missing",
			args:          []string{"name"},
			expectedError: "name and value required",
		},
		{
			about:         "no args",
			args:          []string{},
			expectedError: "name and value required",
		},
	}
	for i, test := range tests {
		c.Logf("test %d: %s", i, test.about)
		if test.expectedError != "" {
			s.mockAPI.SetErrors(errors.New(test.expectedError))
		}
		createCmd := createbudget.NewCreateBudgetCommand()
		_, err := cmdtesting.RunCommand(c, createCmd, test.args...)
		c.Assert(err, gc.ErrorMatches, test.expectedError)
		s.mockAPI.CheckNoCalls(c)
	}
}
コード例 #12
0
ファイル: allocate_test.go プロジェクト: tasdomas/romulus-1
func (s *allocateSuite) TestAllocate(c *gc.C) {
	s.mockAPI.resp = "allocation updated"
	alloc := allocate.NewAllocateCommand()
	ctx, err := cmdtesting.RunCommand(c, alloc, "name:100", "db")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, "allocation updated")
	s.mockAPI.CheckCall(c, 0, "CreateAllocation", "name", "100", "env-uuid", []string{"db"})
}
コード例 #13
0
func (s *updateAllocationSuite) TestUpdateAllocation(c *gc.C) {
	s.mockAPI.resp = "name budget set to 5"
	set := updateallocation.NewUpdateAllocationCommand()
	ctx, err := cmdtesting.RunCommand(c, set, "name", "5")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, "name budget set to 5")
	s.mockAPI.CheckCall(c, 0, "UpdateAllocation", "env-uuid", "name", "5")
}
コード例 #14
0
func (s *listBudgetsSuite) TestListBudgetsNoOutput(c *gc.C) {
	listBudgets := listbudgets.NewListBudgetsCommand()

	ctx, err := cmdtesting.RunCommand(c, listBudgets)
	c.Assert(err, gc.ErrorMatches, `no budget information available`)
	c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, ``)
	s.mockAPI.CheckCallNames(c, "ListBudgets")
}
コード例 #15
0
func (s *deleteCharmSuite) TestRunNotFound(c *gc.C) {
	configPath := s.createConfigFile(c)

	// Deleting charm that does not exist returns a not found error.
	config := &DeleteCharmCommand{}
	_, err := cmdtesting.RunCommand(c, config, "--config", configPath, "--url", "cs:unreleased/foo")
	c.Assert(err, gc.Equals, charmstore.ErrNotFound)
}
コード例 #16
0
func (s *createBudgetSuite) TestCreateBudget(c *gc.C) {
	s.mockAPI.resp = "name budget set to 5"
	createCmd := createbudget.NewCreateBudgetCommand()
	ctx, err := cmdtesting.RunCommand(c, createCmd, "name", "5")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, "name budget set to 5")
	s.mockAPI.CheckCall(c, 0, "CreateBudget", "name", "5")
}
コード例 #17
0
ファイル: setbudget_test.go プロジェクト: bac/juju
func (s *setBudgetSuite) TestSetBudget(c *gc.C) {
	s.mockAPI.resp = "name budget set to 5"
	set := setbudget.NewSetBudgetCommand()
	ctx, err := cmdtesting.RunCommand(c, set, "name", "5")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, "name budget set to 5\n")
	s.mockAPI.CheckCall(c, 0, "SetBudget", "name", "5")
}
コード例 #18
0
ファイル: help_test.go プロジェクト: juju/cmd
func (s *HelpCommandSuite) TestHelpBasics(c *gc.C) {
	super := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "jujutest"})
	super.Register(&TestCommand{Name: "blah"})
	super.AddHelpTopic("basics", "short", "long help basics")

	ctx, err := cmdtesting.RunCommand(c, super)
	c.Assert(err, jc.ErrorIsNil)
	s.assertStdOutMatches(c, ctx, "long help basics")
}
コード例 #19
0
func (s *listBudgetsSuite) TestListBudgetsOutput(c *gc.C) {
	s.mockAPI.result = &budget.ListBudgetsResponse{
		Budgets: budget.BudgetSummaries{
			budget.BudgetSummary{
				Owner:       "bob",
				Budget:      "personal",
				Limit:       "50",
				Allocated:   "30",
				Unallocated: "20",
				Available:   "45",
				Consumed:    "5",
			},
			budget.BudgetSummary{
				Owner:       "bob",
				Budget:      "work",
				Limit:       "200",
				Allocated:   "100",
				Unallocated: "100",
				Available:   "150",
				Consumed:    "50",
			},
			budget.BudgetSummary{
				Owner:       "bob",
				Budget:      "team",
				Limit:       "50",
				Allocated:   "10",
				Unallocated: "40",
				Available:   "40",
				Consumed:    "10",
			},
		},
		Total: budget.BudgetTotals{
			Limit:       "300",
			Allocated:   "140",
			Available:   "235",
			Unallocated: "160",
			Consumed:    "65",
		},
		Credit: "400",
	}
	// Expected command output. Make sure budgets are sorted alphabetically.
	expected := "" +
		"BUDGET       \tMONTHLY\tALLOCATED\tAVAILABLE\tSPENT\n" +
		"personal     \t     50\t       30\t       45\t    5\n" +
		"team         \t     50\t       10\t       40\t   10\n" +
		"work         \t    200\t      100\t      150\t   50\n" +
		"TOTAL        \t    300\t      140\t      235\t   65\n" +
		"             \t       \t         \t         \t     \n" +
		"Credit limit:\t    400\t         \t         \t     \n"

	listBudgets := listbudgets.NewListBudgetsCommand()

	ctx, err := cmdtesting.RunCommand(c, listBudgets)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, expected)
	s.mockAPI.CheckCallNames(c, "ListBudgets")
}
コード例 #20
0
ファイル: help_test.go プロジェクト: juju/cmd
func (s *HelpCommandSuite) TestHelpOutput(c *gc.C) {
	for i, test := range []struct {
		message     string
		args        []string
		usagePrefix string
		helpMatch   string
		errMatch    string
	}{
		{
			message:   "no args shows help",
			helpMatch: "Usage: jujutest .*",
		}, {
			message:     "usage prefix with help command",
			args:        []string{"help"},
			usagePrefix: "juju",
			helpMatch:   "Usage: juju jujutest .*",
		}, {
			message:     "usage prefix with help flag",
			args:        []string{"--help"},
			usagePrefix: "juju",
			helpMatch:   "Usage: juju jujutest .*",
		}, {
			message:   "help arg usage",
			args:      []string{"blah", "--help"},
			helpMatch: "Usage: jujutest blah.*blah-doc.*",
		}, {
			message:     "usage prefix with help command",
			args:        []string{"help", "blah"},
			usagePrefix: "juju",
			helpMatch:   "Usage: juju jujutest blah .*",
		}, {
			message:     "usage prefix with help flag",
			args:        []string{"blah", "--help"},
			usagePrefix: "juju",
			helpMatch:   "Usage: juju jujutest blah .*",
		}, {
			message:  "too many args",
			args:     []string{"help", "blah", "blah"},
			errMatch: `extra arguments to command help: \["blah"\]`,
		},
	} {
		supername := "jujutest"
		super := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: supername, UsagePrefix: test.usagePrefix})
		super.Register(&TestCommand{Name: "blah"})
		c.Logf("%d: %s, %q", i, test.message, strings.Join(append([]string{supername}, test.args...), " "))

		ctx, err := cmdtesting.RunCommand(c, super, test.args...)
		if test.errMatch == "" {
			c.Assert(err, jc.ErrorIsNil)
			s.assertStdOutMatches(c, ctx, test.helpMatch)

		} else {
			c.Assert(err, gc.ErrorMatches, test.errMatch)
		}
	}
}
コード例 #21
0
ファイル: cmd_test.go プロジェクト: tasdomas/romulus-1
func (s *httpSuite) TestNewClient(c *gc.C) {
	basecmd := &testCommand{}
	defer basecmd.Close()

	_, err := cmdtesting.RunCommand(c, basecmd)
	c.Assert(err, jc.ErrorIsNil)

	client, err := basecmd.NewClient()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(client, gc.NotNil)
}
コード例 #22
0
ファイル: agree_test.go プロジェクト: alesstimec/romulus-1
func (s *agreeSuite) TestAgreementNothingToSign(c *gc.C) {
	jujutesting.PatchValue(agree.UserAnswer, func() (string, error) {
		return "y", nil
	})

	s.client.user = "******"
	s.client.setUnsignedTerms([]terms.GetTermsResponse{})

	ctx, err := cmdtesting.RunCommand(c, agree.NewAgreeCommand(), "test-term/1")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(cmdtesting.Stdout(ctx), gc.Equals, `Already agreed
`)
}
コード例 #23
0
ファイル: config_test.go プロジェクト: howbazaar/charmstore
func (s *configSuite) TestReadConfig(c *gc.C) {
	configPath := filepath.Join(c.MkDir(), "charmd.conf")
	err := ioutil.WriteFile(configPath, []byte(testConfig), 0666)
	c.Assert(err, gc.IsNil)

	config := &someConfigCommand{}
	args := []string{"--config", configPath}
	err = cmdtesting.InitCommand(config, args)
	c.Assert(err, gc.IsNil)
	_, err = cmdtesting.RunCommand(c, config, args...)
	c.Assert(err, gc.IsNil)

	c.Assert(config.Config, gc.NotNil)
	c.Assert(config.Config.MongoURL, gc.Equals, "localhost:23456")
}
コード例 #24
0
func (s *showBudgetSuite) TestShowBudgetCommand(c *gc.C) {
	tests := []struct {
		about  string
		args   []string
		err    string
		budget string
		apierr string
	}{{
		about: "missing argument",
		err:   `missing arguments`,
	}, {
		about: "unknown arguments",
		args:  []string{"my-special-budget", "extra", "arguments"},
		err:   `unrecognized args: \["extra" "arguments"\]`,
	}, {
		about:  "api error",
		args:   []string{"personal"},
		apierr: "well, this is embarrassing",
		err:    "failed to retrieve the budget: well, this is embarrassing",
	}, {
		about:  "all ok",
		args:   []string{"personal"},
		budget: "personal",
	},
	}

	for i, test := range tests {
		c.Logf("running test %d: %v", i, test.about)
		s.mockAPI.ResetCalls()

		if test.apierr != "" {
			s.mockAPI.SetErrors(errors.New(test.apierr))
		}

		showBudget := showbudget.NewShowBudgetCommand()

		_, err := cmdtesting.RunCommand(c, showBudget, test.args...)
		if test.err == "" {
			c.Assert(err, jc.ErrorIsNil)
			s.stub.CheckCalls(c, []testing.StubCall{{"GetBudget", []interface{}{test.budget}}})
		} else {
			c.Assert(err, gc.ErrorMatches, test.err)
		}
	}
}
コード例 #25
0
func (s *deleteCharmSuite) TestRunFound(c *gc.C) {
	configPath := s.createConfigFile(c)

	// Publish that charm.
	url := charm.MustParseURL("cs:unreleased/foo")
	store, err := charmstore.Open(gitjujutesting.MgoServer.Addr())
	c.Assert(err, gc.IsNil)
	defer store.Close()
	pub, err := store.CharmPublisher([]*charm.URL{url}, "such-digest-much-unique")
	c.Assert(err, gc.IsNil)
	err = pub.Publish(charmtesting.Charms.ClonedDir(c.MkDir(), "dummy"))
	c.Assert(err, gc.IsNil)

	// The charm is successfully deleted.
	config := &DeleteCharmCommand{}
	_, err = cmdtesting.RunCommand(c, config, "--config", configPath, "--url", "cs:unreleased/foo")
	c.Assert(err, gc.IsNil)
	c.Assert(config.Config, gc.NotNil)

	// Confirm that the charm is gone
	_, err = store.CharmInfo(url)
	c.Assert(err, gc.Equals, charmstore.ErrNotFound)
}
コード例 #26
0
ファイル: show_budget_test.go プロジェクト: bac/juju
func (s *showBudgetSuite) TestShowBudgetCommand(c *gc.C) {
	tests := []struct {
		about      string
		args       []string
		err        string
		budget     string
		apierr     string
		resolveerr string
		output     string
	}{{
		about: "missing argument",
		err:   `missing arguments`,
	}, {
		about: "unknown arguments",
		args:  []string{"my-special-budget", "extra", "arguments"},
		err:   `unrecognized args: \["extra" "arguments"\]`,
	}, {
		about:  "api error",
		args:   []string{"personal"},
		apierr: "well, this is embarrassing",
		err:    "failed to retrieve the budget: well, this is embarrassing",
	}, {
		about:  "all ok",
		args:   []string{"personal"},
		budget: "personal",
		output: "" +
			"MODEL      \tSERVICES \tSPENT\tALLOCATED\tBY       \tUSAGE\n" +
			"model.joe  \tmysql    \t  200\t     1200\tuser.joe \t  42%\n" +
			"           \twordpress\t  300\t         \t         \n" +
			"model.jess \tlandscape\t  600\t     1000\tuser.jess\t  60%\n" +
			"uuid3      \tmysql    \t   10\t      100\tuser.bob \t  10%\n" +
			"           \t         \t     \t         \t         \n" +
			"TOTAL      \t         \t 1110\t     2300\t         \t  48%\n" +
			"BUDGET     \t         \t     \t     4000\t         \n" +
			"UNALLOCATED\t         \t     \t     1700\t         \n",
	}, {
		about:      "all ok",
		args:       []string{"personal"},
		budget:     "personal",
		resolveerr: "test error",
		output: "" +
			"MODEL      \tSERVICES \tSPENT\tALLOCATED\tBY       \tUSAGE\n" +
			"uuid1      \tmysql    \t  200\t     1200\tuser.joe \t  42%\n" +
			"           \twordpress\t  300\t         \t         \n" +
			"uuid2      \tlandscape\t  600\t     1000\tuser.jess\t  60%\n" +
			"uuid3      \tmysql    \t   10\t      100\tuser.bob \t  10%\n" +
			"           \t         \t     \t         \t         \n" +
			"TOTAL      \t         \t 1110\t     2300\t         \t  48%\n" +
			"BUDGET     \t         \t     \t     4000\t         \n" +
			"UNALLOCATED\t         \t     \t     1700\t         \n",
	},
	}

	for i, test := range tests {
		c.Logf("running test %d: %v", i, test.about)
		s.mockAPI.ResetCalls()

		errs := []error{}
		if test.apierr != "" {
			errs = append(errs, errors.New(test.apierr))
		} else {
			errs = append(errs, nil)
		}
		if test.resolveerr != "" {
			errs = append(errs, errors.New(test.resolveerr))
		} else {
			errs = append(errs, nil)
		}
		s.mockAPI.SetErrors(errs...)

		showBudget := showbudget.NewShowBudgetCommand()

		ctx, err := cmdtesting.RunCommand(c, showBudget, test.args...)
		if test.err == "" {
			c.Assert(err, jc.ErrorIsNil)
			s.stub.CheckCalls(c, []testing.StubCall{
				{"GetBudget", []interface{}{test.budget}},
				{"ModelInfo", []interface{}{[]names.ModelTag{names.NewModelTag("uuid1"), names.NewModelTag("uuid2"), names.NewModelTag("uuid3")}}},
			})
			output := cmdtesting.Stdout(ctx)
			c.Assert(output, gc.Equals, test.output)
		} else {
			c.Assert(err, gc.ErrorMatches, test.err)
		}
	}
}
コード例 #27
0
ファイル: agree_test.go プロジェクト: alesstimec/romulus-1
func (s *agreeSuite) TestAgreement(c *gc.C) {
	var answer string
	jujutesting.PatchValue(agree.UserAnswer, func() (string, error) {
		return answer, nil
	})

	s.client.user = "******"
	s.client.setUnsignedTerms([]terms.GetTermsResponse{{
		Name:     "test-term",
		Revision: 1,
		Content:  testTerms,
	}})
	tests := []struct {
		about    string
		args     []string
		err      string
		stdout   string
		answer   string
		apiCalls []jujutesting.StubCall
	}{{
		about:    "everything works",
		args:     []string{"test-term/1", "--yes"},
		stdout:   "Agreed to revision 1 of test-term for Juju users\n",
		apiCalls: []jujutesting.StubCall{{FuncName: "SaveAgreement", Args: []interface{}{&terms.SaveAgreements{Agreements: []terms.SaveAgreement{{TermName: "test-term", TermRevision: 1}}}}}},
	}, {
		about:    "everything works with owner term",
		args:     []string{"owner/test-term/1", "--yes"},
		stdout:   "Agreed to revision 1 of test-term for Juju users\n",
		apiCalls: []jujutesting.StubCall{{FuncName: "SaveAgreement", Args: []interface{}{&terms.SaveAgreements{Agreements: []terms.SaveAgreement{{TermOwner: "owner", TermName: "test-term", TermRevision: 1}}}}}},
	}, {
		about: "cannot parse revision number",
		args:  []string{"test-term/abc"},
		err:   "invalid term format: strconv.ParseInt: parsing \"abc\": invalid syntax",
	}, {
		about: "missing arguments",
		args:  []string{},
		err:   "missing arguments",
	}, {
		about:  "everything works - user accepts",
		args:   []string{"test-term/1"},
		answer: "y",
		stdout: `
=== test-term/1: 0001-01-01 00:00:00 +0000 UTC ===
Test Terms
========
Do you agree to the displayed terms? (Y/n): Agreed to revision 1 of test-term for Juju users
`,
		apiCalls: []jujutesting.StubCall{{
			FuncName: "GetUnunsignedTerms", Args: []interface{}{
				&terms.CheckAgreementsRequest{Terms: []string{"test-term/1"}},
			},
		}, {
			FuncName: "SaveAgreement", Args: []interface{}{
				&terms.SaveAgreements{Agreements: []terms.SaveAgreement{{TermName: "test-term", TermRevision: 1}}},
			},
		}},
	}, {
		about:  "everything works - user refuses",
		args:   []string{"test-term/1"},
		answer: "n",
		stdout: `
=== test-term/1: 0001-01-01 00:00:00 +0000 UTC ===
Test Terms
========
Do you agree to the displayed terms? (Y/n): You didn't agree to the presented terms.
`,
		apiCalls: []jujutesting.StubCall{{
			FuncName: "GetUnunsignedTerms", Args: []interface{}{
				&terms.CheckAgreementsRequest{Terms: []string{"test-term/1"}},
			},
		}},
	}, {
		about: "must not accept 0 revision",
		args:  []string{"test-term/0", "--yes"},
		err:   `must specify a valid term revision "test-term/0"`,
	}, {
		about:  "user accepts, multiple terms",
		args:   []string{"test-term/1", "test-term/2"},
		answer: "y",
		stdout: `
=== test-term/1: 0001-01-01 00:00:00 +0000 UTC ===
Test Terms
========
Do you agree to the displayed terms? (Y/n): Agreed to revision 1 of test-term for Juju users
`,
		apiCalls: []jujutesting.StubCall{
			{
				FuncName: "GetUnunsignedTerms", Args: []interface{}{
					&terms.CheckAgreementsRequest{Terms: []string{"test-term/1", "test-term/2"}},
				},
			}, {
				FuncName: "SaveAgreement", Args: []interface{}{
					&terms.SaveAgreements{Agreements: []terms.SaveAgreement{
						{TermName: "test-term", TermRevision: 1},
					}},
				},
			}},
	}, {
		about: "valid then unknown arguments",
		args:  []string{"test-term/1", "unknown", "arguments"},
		err:   `must specify a valid term revision "unknown"`,
	}, {
		about: "user accepts all the terms",
		args:  []string{"test-term/1", "test-term/2", "--yes"},
		stdout: `Agreed to revision 1 of test-term for Juju users
Agreed to revision 2 of test-term for Juju users
`,
		apiCalls: []jujutesting.StubCall{
			{FuncName: "SaveAgreement", Args: []interface{}{&terms.SaveAgreements{
				Agreements: []terms.SaveAgreement{
					{TermName: "test-term", TermRevision: 1},
					{TermName: "test-term", TermRevision: 2},
				}}}}},
	},
	}
	for i, test := range tests {
		s.client.ResetCalls()
		c.Logf("running test %d: %s", i, test.about)
		if test.answer != "" {
			answer = test.answer
		}
		ctx, err := cmdtesting.RunCommand(c, agree.NewAgreeCommand(), test.args...)
		if test.err != "" {
			c.Assert(err, gc.ErrorMatches, test.err)
		} else {
			c.Assert(err, jc.ErrorIsNil)
		}
		if ctx != nil {
			c.Assert(cmdtesting.Stdout(ctx), gc.Equals, test.stdout)
		}
		if len(test.apiCalls) > 0 {
			s.client.CheckCalls(c, test.apiCalls)
		}
	}
}
コード例 #28
0
ファイル: updateallocation_test.go プロジェクト: bac/juju
func (s *updateAllocationSuite) run(c *gc.C, args ...string) (*cmd.Context, error) {
	updateAlloc := updateallocation.NewUpdateAllocateCommandForTest(s.mockAPI, s.store)
	a := []string{"-m", "controller:model"}
	a = append(a, args...)
	return cmdtesting.RunCommand(c, updateAlloc, a...)
}
コード例 #29
0
ファイル: set_plan_test.go プロジェクト: bac/juju
func (s setPlanCommandSuite) TestSetPlanCommand(c *gc.C) {
	tests := []struct {
		about       string
		plan        string
		application string
		err         string
		apiErr      error
		apiCalls    []testing.StubCall
	}{{
		about:       "all is well",
		plan:        "bob/default",
		application: "mysql",
		apiCalls: []testing.StubCall{{
			FuncName: "Authorize",
			Args: []interface{}{
				s.State.ModelUUID(),
				s.charmURL,
				"mysql",
			},
		}},
	}, {
		about:       "invalid application name",
		plan:        "bob/default",
		application: "mysql-0",
		err:         "invalid application name \"mysql-0\"",
	}, {
		about:       "unknown application",
		plan:        "bob/default",
		application: "wordpress",
		err:         "application \"wordpress\" not found.*",
	}, {
		about:       "unknown application",
		plan:        "bob/default",
		application: "mysql",
		apiErr:      errors.New("some strange error"),
		err:         "some strange error",
	},
	}
	for i, test := range tests {
		c.Logf("running test %d: %v", i, test.about)
		s.mockAPI.ResetCalls()
		if test.apiErr != nil {
			s.mockAPI.SetErrors(test.apiErr)
		}
		_, err := cmdtesting.RunCommand(c, setplan.NewSetPlanCommand(), test.application, test.plan)
		if test.err == "" {
			c.Assert(err, jc.ErrorIsNil)
			c.Assert(s.mockAPI.Calls(), gc.HasLen, 1)
			s.mockAPI.CheckCalls(c, test.apiCalls)

			app, err := s.State.Application("mysql")
			c.Assert(err, jc.ErrorIsNil)
			svcMacaroon := app.MetricCredentials()
			data, err := json.Marshal(macaroon.Slice{s.mockAPI.macaroon})
			c.Assert(err, jc.ErrorIsNil)
			c.Assert(svcMacaroon, gc.DeepEquals, data)
		} else {
			c.Assert(err, gc.ErrorMatches, test.err)
			c.Assert(s.mockAPI.Calls(), gc.HasLen, 0)
		}
	}
}
コード例 #30
0
ファイル: set_plan_test.go プロジェクト: bac/juju
func (s *setPlanCommandSuite) TestNoArgs(c *gc.C) {
	_, err := cmdtesting.RunCommand(c, setplan.NewSetPlanCommand())
	c.Assert(err, gc.ErrorMatches, "need to specify application name and plan url")
}