1
// Copyright 2012, 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
8
jc "github.com/juju/testing/checkers"
9
"github.com/juju/utils/series"
10
gc "gopkg.in/check.v1"
12
"github.com/juju/juju/cmd/jujud/agent/agenttest"
13
cmdutil "github.com/juju/juju/cmd/jujud/util"
14
imagetesting "github.com/juju/juju/environs/imagemetadata/testing"
15
"github.com/juju/juju/juju/paths"
16
"github.com/juju/juju/mongo"
17
"github.com/juju/juju/network"
18
coretesting "github.com/juju/juju/testing"
19
"github.com/juju/juju/worker"
20
"github.com/juju/juju/worker/proxyupdater"
23
type acCreator func() (cmd.Command, AgentConf)
25
// CheckAgentCommand is a utility function for verifying that common agent
26
// options are handled by a Command; it returns an instance of that
27
// command pre-parsed, with any mandatory flags added.
28
func CheckAgentCommand(c *gc.C, create acCreator, args []string) cmd.Command {
30
err := coretesting.InitCommand(com, args)
31
dataDir, err := paths.DataDir(series.HostSeries())
32
c.Assert(err, jc.ErrorIsNil)
33
c.Assert(conf.DataDir(), gc.Equals, dataDir)
34
badArgs := append(args, "--data-dir", "")
36
err = coretesting.InitCommand(com, badArgs)
37
c.Assert(err, gc.ErrorMatches, "--data-dir option must be set")
39
args = append(args, "--data-dir", "jd")
41
c.Assert(coretesting.InitCommand(com, args), gc.IsNil)
42
c.Assert(conf.DataDir(), gc.Equals, "jd")
46
// ParseAgentCommand is a utility function that inserts the always-required args
47
// before parsing an agent command and returning the result.
48
func ParseAgentCommand(ac cmd.Command, args []string) error {
52
return coretesting.InitCommand(ac, append(common, args...))
55
// AgentSuite is a fixture to be used by agent test suites.
56
type AgentSuite struct {
60
func (s *AgentSuite) SetUpSuite(c *gc.C) {
61
s.JujuConnSuite.SetUpSuite(c)
63
s.PatchValue(&cmdutil.EnsureMongoServer, func(mongo.EnsureServerParams) error {
68
func (s *AgentSuite) SetUpTest(c *gc.C) {
69
s.JujuConnSuite.SetUpTest(c)
70
// Set API host ports so FindTools/Tools API calls succeed.
71
hostPorts := [][]network.HostPort{
72
network.NewHostPorts(1234, "0.1.2.3"),
74
err := s.State.SetAPIHostPorts(hostPorts)
75
c.Assert(err, jc.ErrorIsNil)
76
s.PatchValue(&proxyupdater.NewWorker, func(proxyupdater.Config) (worker.Worker, error) {
77
return newDummyWorker(), nil
80
// Tests should not try to use internet. Ensure base url is empty.
81
imagetesting.PatchOfficialDataSources(&s.CleanupSuite, "")