LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package main | 4 package main |
5 | 5 |
6 import ( | 6 import ( |
7 "bytes" | 7 "bytes" |
8 "fmt" | 8 "fmt" |
9 "io/ioutil" | 9 "io/ioutil" |
10 "net/url" | 10 "net/url" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 about: "scp from unit mongodb/1 to unit mongodb/0 and multiple
extra args", | 71 about: "scp from unit mongodb/1 to unit mongodb/0 and multiple
extra args", |
72 args: []string{"mongodb/1:foo", "mongodb/0:", "-r", "-v", "-q"
, "-l5"}, | 72 args: []string{"mongodb/1:foo", "mongodb/0:", "-r", "-v", "-q"
, "-l5"}, |
73 result: commonArgsNoProxy + "ubuntu@dummyenv-2.dns:foo ubuntu@du
mmyenv-1.dns: -r -v -q -l5\n", | 73 result: commonArgsNoProxy + "ubuntu@dummyenv-2.dns:foo ubuntu@du
mmyenv-1.dns: -r -v -q -l5\n", |
74 }, { | 74 }, { |
75 about: "scp works with IPv6 addresses", | 75 about: "scp works with IPv6 addresses", |
76 args: []string{"ipv6-svc/0:foo", "bar"}, | 76 args: []string{"ipv6-svc/0:foo", "bar"}, |
77 result: commonArgsNoProxy + `ubuntu@\[2001:db8::\]:foo bar` + "\
n", | 77 result: commonArgsNoProxy + `ubuntu@\[2001:db8::\]:foo bar` + "\
n", |
78 }, { | 78 }, { |
79 about: "scp from machine 0 to unit mysql/0 with proxy", | 79 about: "scp from machine 0 to unit mysql/0 with proxy", |
80 args: []string{"0:foo", "mysql/0:/foo"}, | 80 args: []string{"0:foo", "mysql/0:/foo"}, |
81 » » result: commonArgs + "ubuntu@dummyenv-0.dns:foo ubuntu@dummyenv-
0.dns:/foo\n", | 81 » » result: commonArgs + "ubuntu@dummyenv-0.internal:foo ubuntu@dumm
yenv-0.internal:/foo\n", |
82 proxy: true, | 82 proxy: true, |
83 }, { | 83 }, { |
84 args: []string{"0:foo", ".", "-rv", "-o", "SomeOption"}, | 84 args: []string{"0:foo", ".", "-rv", "-o", "SomeOption"}, |
85 result: commonArgsNoProxy + "ubuntu@dummyenv-0.dns:foo . -rv -o
SomeOption\n", | 85 result: commonArgsNoProxy + "ubuntu@dummyenv-0.dns:foo . -rv -o
SomeOption\n", |
86 }, { | 86 }, { |
87 args: []string{"foo", "0:", "-r", "-v"}, | 87 args: []string{"foo", "0:", "-r", "-v"}, |
88 result: commonArgsNoProxy + "foo ubuntu@dummyenv-0.dns: -r -v\n"
, | 88 result: commonArgsNoProxy + "foo ubuntu@dummyenv-0.dns: -r -v\n"
, |
89 }, { | 89 }, { |
90 args: []string{"mongodb/1:foo", "mongodb/0:", "-r", "-v", "-q"
, "-l5"}, | 90 args: []string{"mongodb/1:foo", "mongodb/0:", "-r", "-v", "-q"
, "-l5"}, |
91 result: commonArgsNoProxy + "ubuntu@dummyenv-2.dns:foo ubuntu@du
mmyenv-1.dns: -r -v -q -l5\n", | 91 result: commonArgsNoProxy + "ubuntu@dummyenv-2.dns:foo ubuntu@du
mmyenv-1.dns: -r -v -q -l5\n", |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 if t.proxy { | 181 if t.proxy { |
182 c.Check(strings.HasPrefix(t.result, commonArgs), jc.IsTr
ue) | 182 c.Check(strings.HasPrefix(t.result, commonArgs), jc.IsTr
ue) |
183 argString = t.result[len(commonArgs):] | 183 argString = t.result[len(commonArgs):] |
184 } else { | 184 } else { |
185 c.Check(strings.HasPrefix(t.result, commonArgsNoProxy),
jc.IsTrue) | 185 c.Check(strings.HasPrefix(t.result, commonArgsNoProxy),
jc.IsTrue) |
186 argString = t.result[len(commonArgsNoProxy):] | 186 argString = t.result[len(commonArgsNoProxy):] |
187 } | 187 } |
188 c.Check(strings.HasSuffix(argString, "\n"), jc.IsTrue) | 188 c.Check(strings.HasSuffix(argString, "\n"), jc.IsTrue) |
189 argString = argString[:len(argString)-1] | 189 argString = argString[:len(argString)-1] |
190 args := strings.Split(argString, " ") | 190 args := strings.Split(argString, " ") |
191 » » expanded, err := expandArgs(t.args, dummyHostsFromTarget) | 191 » » expanded, err := expandArgs(t.args, func(target string) (string,
error) { |
| 192 » » » if res, ok := hostsFromTargets[target]; ok { |
| 193 » » » » if t.proxy { |
| 194 » » » » » res = strings.Replace(res, ".dns", ".int
ernal", 1) |
| 195 » » » » } |
| 196 » » » » return res, nil |
| 197 » » » } |
| 198 » » » return target, nil |
| 199 » » }) |
192 c.Check(err, gc.IsNil) | 200 c.Check(err, gc.IsNil) |
193 c.Check(expanded, gc.DeepEquals, args) | 201 c.Check(expanded, gc.DeepEquals, args) |
194 } | 202 } |
195 } | 203 } |
196 | 204 |
197 var expandTests = []struct { | 205 var expandTests = []struct { |
198 about string | 206 about string |
199 args []string | 207 args []string |
200 result []string | 208 result []string |
201 }{ | 209 }{ |
(...skipping 14 matching lines...) Expand all Loading... |
216 } | 224 } |
217 | 225 |
218 func (s *expandArgsSuite) TestExpandArgsPropagatesErrors(c *gc.C) { | 226 func (s *expandArgsSuite) TestExpandArgsPropagatesErrors(c *gc.C) { |
219 erroringHostFromTargets := func(string) (string, error) { | 227 erroringHostFromTargets := func(string) (string, error) { |
220 return "", fmt.Errorf("this is my error") | 228 return "", fmt.Errorf("this is my error") |
221 } | 229 } |
222 expanded, err := expandArgs([]string{"foo:1", "bar"}, erroringHostFromTa
rgets) | 230 expanded, err := expandArgs([]string{"foo:1", "bar"}, erroringHostFromTa
rgets) |
223 c.Assert(err, gc.ErrorMatches, "this is my error") | 231 c.Assert(err, gc.ErrorMatches, "this is my error") |
224 c.Check(expanded, gc.IsNil) | 232 c.Check(expanded, gc.IsNil) |
225 } | 233 } |
LEFT | RIGHT |