~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/featuretests/cmdjuju_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2015 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package featuretests
 
5
 
 
6
import (
 
7
        jc "github.com/juju/testing/checkers"
 
8
        gc "gopkg.in/check.v1"
 
9
        "gopkg.in/juju/charm.v6-unstable"
 
10
 
 
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"
 
18
)
 
19
 
 
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
 
26
}
 
27
 
 
28
func uint64p(val uint64) *uint64 {
 
29
        return &val
 
30
}
 
31
 
 
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)
 
35
 
 
36
        cons, err := s.State.ModelConstraints()
 
37
        c.Assert(err, jc.ErrorIsNil)
 
38
        c.Assert(cons, gc.DeepEquals, constraints.Value{
 
39
                CpuPower: uint64p(250),
 
40
                Mem:      uint64p(4096),
 
41
        })
 
42
}
 
43
 
 
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)
 
48
 
 
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, "")
 
52
}
 
53
 
 
54
func (s *cmdJujuSuite) TestServiceSet(c *gc.C) {
 
55
        ch := s.AddTestingCharm(c, "dummy")
 
56
        svc := s.AddTestingService(c, "dummy-service", ch)
 
57
 
 
58
        _, err := testing.RunCommand(c, application.NewSetCommand(), "dummy-service",
 
59
                "username=hello", "outlook=hello@world.tld")
 
60
        c.Assert(err, jc.ErrorIsNil)
 
61
 
 
62
        expect := charm.Settings{
 
63
                "username": "hello",
 
64
                "outlook":  "hello@world.tld",
 
65
        }
 
66
 
 
67
        settings, err := svc.ConfigSettings()
 
68
        c.Assert(err, jc.ErrorIsNil)
 
69
        c.Assert(settings, gc.DeepEquals, expect)
 
70
}
 
71
 
 
72
func (s *cmdJujuSuite) TestServiceUnset(c *gc.C) {
 
73
        ch := s.AddTestingCharm(c, "dummy")
 
74
        svc := s.AddTestingService(c, "dummy-service", ch)
 
75
 
 
76
        settings := charm.Settings{
 
77
                "username": "hello",
 
78
                "outlook":  "hello@world.tld",
 
79
        }
 
80
 
 
81
        err := svc.UpdateConfigSettings(settings)
 
82
        c.Assert(err, jc.ErrorIsNil)
 
83
 
 
84
        _, err = testing.RunCommand(c, application.NewSetCommand(), "--to-default", "dummy-service", "username")
 
85
        c.Assert(err, jc.ErrorIsNil)
 
86
 
 
87
        expect := charm.Settings{
 
88
                "outlook": "hello@world.tld",
 
89
        }
 
90
        settings, err = svc.ConfigSettings()
 
91
        c.Assert(err, jc.ErrorIsNil)
 
92
        c.Assert(settings, gc.DeepEquals, expect)
 
93
}
 
94
 
 
95
func (s *cmdJujuSuite) TestServiceGet(c *gc.C) {
 
96
        expected := `application: dummy-service
 
97
charm: dummy
 
98
settings:
 
99
  outlook:
 
100
    default: true
 
101
    description: No default outlook.
 
102
    type: string
 
103
  skill-level:
 
104
    default: true
 
105
    description: A number indicating skill.
 
106
    type: int
 
107
  title:
 
108
    default: true
 
109
    description: A descriptive title used for the application.
 
110
    type: string
 
111
    value: My Title
 
112
  username:
 
113
    default: true
 
114
    description: The name of the initial account (given admin permissions).
 
115
    type: string
 
116
    value: admin001
 
117
`
 
118
        ch := s.AddTestingCharm(c, "dummy")
 
119
        s.AddTestingService(c, "dummy-service", ch)
 
120
 
 
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)
 
124
}
 
125
 
 
126
func (s *cmdJujuSuite) TestServiceAddUnitExistingContainer(c *gc.C) {
 
127
        ch := s.AddTestingCharm(c, "dummy")
 
128
        svc := s.AddTestingService(c, "some-application-name", ch)
 
129
 
 
130
        machine, err := s.State.AddMachine("quantal", state.JobHostUnits)
 
131
        c.Assert(err, jc.ErrorIsNil)
 
132
        template := state.MachineTemplate{
 
133
                Series: "quantal",
 
134
                Jobs:   []state.MachineJob{state.JobHostUnits},
 
135
        }
 
136
        container, err := s.State.AddMachineInsideMachine(template, machine.Id(), instance.LXD)
 
137
        c.Assert(err, jc.ErrorIsNil)
 
138
 
 
139
        _, err = testing.RunCommand(c, application.NewAddUnitCommand(), "some-application-name",
 
140
                "--to", container.Id())
 
141
        c.Assert(err, jc.ErrorIsNil)
 
142
 
 
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())
 
148
}