Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(66)

Side by Side Diff: cmd/juju/environment_test.go

Issue 8610043: Implement the set-environment command.
Patch Set: Created 10 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 package main 1 package main
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 . "launchpad.net/gocheck" 5 . "launchpad.net/gocheck"
6 "launchpad.net/juju-core/testing" 6 "launchpad.net/juju-core/testing"
7 "strings" 7 "strings"
8 ) 8 )
9 9
10 type GetEnvironmentSuite struct { 10 type GetEnvironmentSuite struct {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 context, _ := testing.RunCommand(c, &GetEnvironmentCommand{}, []string{} ) 57 context, _ := testing.RunCommand(c, &GetEnvironmentCommand{}, []string{} )
58 output := strings.TrimSpace(testing.Stdout(context)) 58 output := strings.TrimSpace(testing.Stdout(context))
59 59
60 // Make sure that all the environment keys are there. 60 // Make sure that all the environment keys are there.
61 any := "(.|\n)*" // because . doesn't match new lines. 61 any := "(.|\n)*" // because . doesn't match new lines.
62 for key, _ := range s.Conn.Environ.Config().AllAttrs() { 62 for key, _ := range s.Conn.Environ.Config().AllAttrs() {
63 c.Assert(output, Matches, fmt.Sprintf("%s%s: %s", any, key, any) ) 63 c.Assert(output, Matches, fmt.Sprintf("%s%s: %s", any, key, any) )
64 } 64 }
65 } 65 }
66
67 type SetEnvironmentSuite struct {
68 repoSuite
69 }
70
71 var _ = Suite(&SetEnvironmentSuite{})
72
73 var setEnvInitTests = []struct {
74 args []string
75 expected attributes
76 err string
77 }{
78 {
79 args: []string{},
80 err: "No key, value pairs specified",
81 }, {
82 args: []string{"missing"},
83 err: `Missing "=" in arg 1: "missing"`,
84 }, {
85 args: []string{"key=value"},
86 expected: attributes{
87 "key": "value",
88 },
89 }, {
90 args: []string{"key=value", "key=other"},
91 err: `Key "key" specified more than once`,
92 }, {
93 args: []string{"key=value", "other=embedded=equal"},
94 expected: attributes{
95 "key": "value",
96 "other": "embedded=equal",
97 },
98 },
99 }
100
101 func (s *SetEnvironmentSuite) TestInit(c *C) {
102
103 for _, t := range setEnvInitTests {
104 command := &SetEnvironmentCommand{}
105 testing.TestInit(c, command, t.args, t.err)
106 if t.expected != nil {
107 c.Assert(command.values, DeepEquals, t.expected)
108 }
109 }
110 }
111
112 func (s *SetEnvironmentSuite) TestChangeDefaultSeries(c *C) {
113 _, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []string{"defa ult-series=raring"})
114 c.Assert(err, IsNil)
115
116 stateConfig, err := s.State.EnvironConfig()
117 c.Assert(err, IsNil)
118 c.Assert(stateConfig.DefaultSeries(), Equals, "raring")
119 }
120
121 func (s *SetEnvironmentSuite) TestChangeAsCommandPair(c *C) {
122 _, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []string{"defa ult-series=raring"})
123 c.Assert(err, IsNil)
124
125 context, err := testing.RunCommand(c, &GetEnvironmentCommand{}, []string {"default-series"})
126 c.Assert(err, IsNil)
127 output := strings.TrimSpace(testing.Stdout(context))
128
129 c.Assert(output, Equals, "raring")
130 }
fwereade 2013/04/10 12:45:20 test for more than one value?
thumper 2013/04/10 23:17:23 Sure... if you feel the need. I do have a test ab
131
132 var immutableConfigTests = map[string]string{
133 "name": "foo",
134 "type": "foo",
135 "agent-version": "1.2.3",
136 "firewall-mode": "global",
137 }
138
139 func (s *SetEnvironmentSuite) TestImmutableConfigValues(c *C) {
140 for name, value := range immutableConfigTests {
fwereade 2013/04/10 12:45:20 I would still prefer a whitelist to a blacklist, b
thumper 2013/04/10 23:17:23 I think that given we already had a way for valida
141 param := fmt.Sprintf("%s=%s", name, value)
142 _, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []stri ng{param})
143 errorPattern := fmt.Sprintf("cannot change %s from .* to %q", na me, value)
144 c.Assert(err, ErrorMatches, errorPattern)
145 }
146 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b