1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
jc "github.com/juju/testing/checkers"
9
"gopkg.in/juju/charm.v6-unstable"
11
"github.com/juju/juju/cmd/juju/application"
12
"github.com/juju/juju/cmd/juju/model"
13
"github.com/juju/juju/constraints"
14
"github.com/juju/juju/instance"
15
jujutesting "github.com/juju/juju/juju/testing"
16
"github.com/juju/juju/state"
17
"github.com/juju/juju/testing"
20
// cmdJujuSuite tests the connectivity of juju commands. These tests
21
// go from the command line, api client, api server, db. The db changes
22
// are then checked. Only one test for each command is done here to
23
// check connectivity. Exhaustive unit tests are at each layer.
24
type cmdJujuSuite struct {
25
jujutesting.JujuConnSuite
28
func uint64p(val uint64) *uint64 {
32
func (s *cmdJujuSuite) TestSetConstraints(c *gc.C) {
33
_, err := testing.RunCommand(c, model.NewModelSetConstraintsCommand(), "mem=4G", "cpu-power=250")
34
c.Assert(err, jc.ErrorIsNil)
36
cons, err := s.State.ModelConstraints()
37
c.Assert(err, jc.ErrorIsNil)
38
c.Assert(cons, gc.DeepEquals, constraints.Value{
39
CpuPower: uint64p(250),
44
func (s *cmdJujuSuite) TestGetConstraints(c *gc.C) {
45
svc := s.AddTestingService(c, "svc", s.AddTestingCharm(c, "dummy"))
46
err := svc.SetConstraints(constraints.Value{CpuCores: uint64p(64)})
47
c.Assert(err, jc.ErrorIsNil)
49
context, err := testing.RunCommand(c, application.NewServiceGetConstraintsCommand(), "svc")
50
c.Assert(testing.Stdout(context), gc.Equals, "cpu-cores=64\n")
51
c.Assert(testing.Stderr(context), gc.Equals, "")
54
func (s *cmdJujuSuite) TestServiceSet(c *gc.C) {
55
ch := s.AddTestingCharm(c, "dummy")
56
svc := s.AddTestingService(c, "dummy-service", ch)
58
_, err := testing.RunCommand(c, application.NewSetCommand(), "dummy-service",
59
"username=hello", "outlook=hello@world.tld")
60
c.Assert(err, jc.ErrorIsNil)
62
expect := charm.Settings{
64
"outlook": "hello@world.tld",
67
settings, err := svc.ConfigSettings()
68
c.Assert(err, jc.ErrorIsNil)
69
c.Assert(settings, gc.DeepEquals, expect)
72
func (s *cmdJujuSuite) TestServiceUnset(c *gc.C) {
73
ch := s.AddTestingCharm(c, "dummy")
74
svc := s.AddTestingService(c, "dummy-service", ch)
76
settings := charm.Settings{
78
"outlook": "hello@world.tld",
81
err := svc.UpdateConfigSettings(settings)
82
c.Assert(err, jc.ErrorIsNil)
84
_, err = testing.RunCommand(c, application.NewSetCommand(), "--to-default", "dummy-service", "username")
85
c.Assert(err, jc.ErrorIsNil)
87
expect := charm.Settings{
88
"outlook": "hello@world.tld",
90
settings, err = svc.ConfigSettings()
91
c.Assert(err, jc.ErrorIsNil)
92
c.Assert(settings, gc.DeepEquals, expect)
95
func (s *cmdJujuSuite) TestServiceGet(c *gc.C) {
96
expected := `application: dummy-service
101
description: No default outlook.
105
description: A number indicating skill.
109
description: A descriptive title used for the application.
114
description: The name of the initial account (given admin permissions).
118
ch := s.AddTestingCharm(c, "dummy")
119
s.AddTestingService(c, "dummy-service", ch)
121
context, err := testing.RunCommand(c, application.NewGetCommand(), "dummy-service")
122
c.Assert(err, jc.ErrorIsNil)
123
c.Assert(testing.Stdout(context), jc.DeepEquals, expected)
126
func (s *cmdJujuSuite) TestServiceAddUnitExistingContainer(c *gc.C) {
127
ch := s.AddTestingCharm(c, "dummy")
128
svc := s.AddTestingService(c, "some-application-name", ch)
130
machine, err := s.State.AddMachine("quantal", state.JobHostUnits)
131
c.Assert(err, jc.ErrorIsNil)
132
template := state.MachineTemplate{
134
Jobs: []state.MachineJob{state.JobHostUnits},
136
container, err := s.State.AddMachineInsideMachine(template, machine.Id(), instance.LXD)
137
c.Assert(err, jc.ErrorIsNil)
139
_, err = testing.RunCommand(c, application.NewAddUnitCommand(), "some-application-name",
140
"--to", container.Id())
141
c.Assert(err, jc.ErrorIsNil)
143
units, err := svc.AllUnits()
144
c.Assert(err, jc.ErrorIsNil)
145
mid, err := units[0].AssignedMachineId()
146
c.Assert(err, jc.ErrorIsNil)
147
c.Assert(mid, gc.Equals, container.Id())