-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmdjuju_test.go
148 lines (124 loc) · 4.32 KB
/
cmdjuju_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package featuretests
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/juju/charm.v6-unstable"
"github.com/juju/juju/cmd/juju/application"
"github.com/juju/juju/cmd/juju/model"
"github.com/juju/juju/constraints"
"github.com/juju/juju/instance"
jujutesting "github.com/juju/juju/juju/testing"
"github.com/juju/juju/state"
"github.com/juju/juju/testing"
)
// cmdJujuSuite tests the connectivity of juju commands. These tests
// go from the command line, api client, api server, db. The db changes
// are then checked. Only one test for each command is done here to
// check connectivity. Exhaustive unit tests are at each layer.
type cmdJujuSuite struct {
jujutesting.JujuConnSuite
}
func uint64p(val uint64) *uint64 {
return &val
}
func (s *cmdJujuSuite) TestSetConstraints(c *gc.C) {
_, err := testing.RunCommand(c, model.NewModelSetConstraintsCommand(), "mem=4G", "cpu-power=250")
c.Assert(err, jc.ErrorIsNil)
cons, err := s.State.ModelConstraints()
c.Assert(err, jc.ErrorIsNil)
c.Assert(cons, gc.DeepEquals, constraints.Value{
CpuPower: uint64p(250),
Mem: uint64p(4096),
})
}
func (s *cmdJujuSuite) TestGetConstraints(c *gc.C) {
svc := s.AddTestingService(c, "svc", s.AddTestingCharm(c, "dummy"))
err := svc.SetConstraints(constraints.Value{CpuCores: uint64p(64)})
c.Assert(err, jc.ErrorIsNil)
context, err := testing.RunCommand(c, application.NewServiceGetConstraintsCommand(), "svc")
c.Assert(testing.Stdout(context), gc.Equals, "cores=64\n")
c.Assert(testing.Stderr(context), gc.Equals, "")
}
func (s *cmdJujuSuite) TestServiceSet(c *gc.C) {
ch := s.AddTestingCharm(c, "dummy")
svc := s.AddTestingService(c, "dummy-service", ch)
_, err := testing.RunCommand(c, application.NewConfigCommand(), "dummy-service",
"username=hello", "outlook=hello@world.tld")
c.Assert(err, jc.ErrorIsNil)
expect := charm.Settings{
"username": "hello",
"outlook": "hello@world.tld",
}
settings, err := svc.ConfigSettings()
c.Assert(err, jc.ErrorIsNil)
c.Assert(settings, gc.DeepEquals, expect)
}
func (s *cmdJujuSuite) TestServiceUnset(c *gc.C) {
ch := s.AddTestingCharm(c, "dummy")
svc := s.AddTestingService(c, "dummy-service", ch)
settings := charm.Settings{
"username": "hello",
"outlook": "hello@world.tld",
}
err := svc.UpdateConfigSettings(settings)
c.Assert(err, jc.ErrorIsNil)
_, err = testing.RunCommand(c, application.NewConfigCommand(), "dummy-service", "--reset", "username")
c.Assert(err, jc.ErrorIsNil)
expect := charm.Settings{
"outlook": "hello@world.tld",
}
settings, err = svc.ConfigSettings()
c.Assert(err, jc.ErrorIsNil)
c.Assert(settings, gc.DeepEquals, expect)
}
func (s *cmdJujuSuite) TestServiceGet(c *gc.C) {
expected := `application: dummy-service
charm: dummy
settings:
outlook:
default: true
description: No default outlook.
type: string
skill-level:
default: true
description: A number indicating skill.
type: int
title:
default: true
description: A descriptive title used for the application.
type: string
value: My Title
username:
default: true
description: The name of the initial account (given admin permissions).
type: string
value: admin001
`
ch := s.AddTestingCharm(c, "dummy")
s.AddTestingService(c, "dummy-service", ch)
context, err := testing.RunCommand(c, application.NewConfigCommand(), "dummy-service")
c.Assert(err, jc.ErrorIsNil)
c.Assert(testing.Stdout(context), jc.DeepEquals, expected)
}
func (s *cmdJujuSuite) TestServiceAddUnitExistingContainer(c *gc.C) {
ch := s.AddTestingCharm(c, "dummy")
svc := s.AddTestingService(c, "some-application-name", ch)
machine, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, jc.ErrorIsNil)
template := state.MachineTemplate{
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
}
container, err := s.State.AddMachineInsideMachine(template, machine.Id(), instance.LXD)
c.Assert(err, jc.ErrorIsNil)
_, err = testing.RunCommand(c, application.NewAddUnitCommand(), "some-application-name",
"--to", container.Id())
c.Assert(err, jc.ErrorIsNil)
units, err := svc.AllUnits()
c.Assert(err, jc.ErrorIsNil)
mid, err := units[0].AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
c.Assert(mid, gc.Equals, container.Id())
}