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

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

Issue 78070043: cmd/juju: revert proxy changes in CLI
Patch Set: Created 10 years 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
« no previous file with comments | « cmd/juju/scp.go ('k') | cmd/juju/ssh.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 "path/filepath" 11 "path/filepath"
12 12
13 gc "launchpad.net/gocheck" 13 gc "launchpad.net/gocheck"
14 14
15 "launchpad.net/juju-core/charm" 15 "launchpad.net/juju-core/charm"
16 "launchpad.net/juju-core/instance" 16 "launchpad.net/juju-core/instance"
17 coretesting "launchpad.net/juju-core/testing" 17 coretesting "launchpad.net/juju-core/testing"
18 ) 18 )
19 19
20 var _ = gc.Suite(&SCPSuite{}) 20 var _ = gc.Suite(&SCPSuite{})
21 21
22 type SCPSuite struct { 22 type SCPSuite struct {
23 SSHCommonSuite 23 SSHCommonSuite
24 } 24 }
25 25
26 var scpTests = []struct { 26 var scpTests = []struct {
27 about string 27 about string
28 args []string 28 args []string
29 result string 29 result string
30 proxy bool
31 error string 30 error string
32 }{ 31 }{
33 { 32 {
34 » » about: "scp from machine 0 to current dir", 33 » » "scp from machine 0 to current dir",
35 » » args: []string{"0:foo", "."}, 34 » » []string{"0:foo", "."},
36 » » result: commonArgsNoProxy + "ubuntu@dummyenv-0.dns:foo .\n", 35 » » commonArgs + "ubuntu@dummyenv-0.dns:foo .\n",
36 » » "",
37 }, 37 },
38 { 38 {
39 » » about: "scp from machine 0 to current dir with extra args", 39 » » "scp from machine 0 to current dir with extra args",
40 » » args: []string{"0:foo", ".", "-rv -o SomeOption"}, 40 » » []string{"0:foo", ".", "-rv -o SomeOption"},
41 » » result: commonArgsNoProxy + "-rv -o SomeOption ubuntu@dummyenv-0 .dns:foo .\n", 41 » » commonArgs + "-rv -o SomeOption ubuntu@dummyenv-0.dns:foo .\n",
42 » » "",
42 }, 43 },
43 { 44 {
44 » » about: "scp from current dir to machine 0", 45 » » "scp from current dir to machine 0",
45 » » args: []string{"foo", "0:"}, 46 » » []string{"foo", "0:"},
46 » » result: commonArgsNoProxy + "foo ubuntu@dummyenv-0.dns:\n", 47 » » commonArgs + "foo ubuntu@dummyenv-0.dns:\n",
48 » » "",
47 }, 49 },
48 { 50 {
49 » » about: "scp from current dir to machine 0 with extra args", 51 » » "scp from current dir to machine 0 with extra args",
50 » » args: []string{"foo", "0:", "-r -v"}, 52 » » []string{"foo", "0:", "-r -v"},
51 » » result: commonArgsNoProxy + "-r -v foo ubuntu@dummyenv-0.dns:\n" , 53 » » commonArgs + "-r -v foo ubuntu@dummyenv-0.dns:\n",
54 » » "",
52 }, 55 },
53 { 56 {
54 » » about: "scp from machine 0 to unit mysql/0", 57 » » "scp from machine 0 to unit mysql/0",
55 » » args: []string{"0:foo", "mysql/0:/foo"}, 58 » » []string{"0:foo", "mysql/0:/foo"},
56 » » result: commonArgsNoProxy + "ubuntu@dummyenv-0.dns:foo ubuntu@du mmyenv-0.dns:/foo\n", 59 » » commonArgs + "ubuntu@dummyenv-0.dns:foo ubuntu@dummyenv-0.dns:/f oo\n",
60 » » "",
57 }, 61 },
58 { 62 {
59 » » about: "scp from machine 0 to unit mysql/0 and extra args", 63 » » "scp from machine 0 to unit mysql/0 and extra args",
60 » » args: []string{"0:foo", "mysql/0:/foo", "-q"}, 64 » » []string{"0:foo", "mysql/0:/foo", "-q"},
61 » » result: commonArgsNoProxy + "-q ubuntu@dummyenv-0.dns:foo ubuntu @dummyenv-0.dns:/foo\n", 65 » » commonArgs + "-q ubuntu@dummyenv-0.dns:foo ubuntu@dummyenv-0.dns :/foo\n",
66 » » "",
62 }, 67 },
63 { 68 {
64 » » about: "scp from machine 0 to unit mysql/0 and extra args before ", 69 » » "scp from machine 0 to unit mysql/0 and extra args before",
65 » » args: []string{"-q", "-r", "0:foo", "mysql/0:/foo"}, 70 » » []string{"-q", "-r", "0:foo", "mysql/0:/foo"},
66 » » error: `unexpected argument "-q"; extra arguments must be last`, 71 » » "",
72 » » `unexpected argument "-q"; extra arguments must be last`,
67 }, 73 },
68 { 74 {
69 » » about: "scp two local files to unit mysql/0", 75 » » "scp two local files to unit mysql/0",
70 » » args: []string{"file1", "file2", "mysql/0:/foo/"}, 76 » » []string{"file1", "file2", "mysql/0:/foo/"},
71 » » result: commonArgsNoProxy + "file1 file2 ubuntu@dummyenv-0.dns:/ foo/\n", 77 » » commonArgs + "file1 file2 ubuntu@dummyenv-0.dns:/foo/\n",
78 » » "",
72 }, 79 },
73 { 80 {
74 » » about: "scp from unit mongodb/1 to unit mongodb/0 and multiple extra args", 81 » » "scp from unit mongodb/1 to unit mongodb/0 and multiple extra ar gs",
75 » » args: []string{"mongodb/1:foo", "mongodb/0:", "-r -v -q -l5"}, 82 » » []string{"mongodb/1:foo", "mongodb/0:", "-r -v -q -l5"},
76 » » result: commonArgsNoProxy + "-r -v -q -l5 ubuntu@dummyenv-2.dns: foo ubuntu@dummyenv-1.dns:\n", 83 » » commonArgs + "-r -v -q -l5 ubuntu@dummyenv-2.dns:foo ubuntu@dumm yenv-1.dns:\n",
84 » » "",
77 }, 85 },
78 { 86 {
79 » » about: "scp works with IPv6 addresses", 87 » » "scp works with IPv6 addresses",
80 » » args: []string{"ipv6-svc/0:foo", "bar"}, 88 » » []string{"ipv6-svc/0:foo", "bar"},
81 » » result: commonArgsNoProxy + `ubuntu@\[2001:db8::\]:foo bar` + "\ n", 89 » » commonArgs + `ubuntu@\[2001:db8::\]:foo bar` + "\n",
82 » }, 90 » » "",
83 » {
84 » » about: "scp from machine 0 to unit mysql/0 with proxy",
85 » » args: []string{"0:foo", "mysql/0:/foo"},
86 » » result: commonArgs + "ubuntu@dummyenv-0.dns:foo ubuntu@dummyenv- 0.dns:/foo\n",
87 » » proxy: true,
88 }, 91 },
89 } 92 }
90 93
91 func (s *SCPSuite) TestSCPCommand(c *gc.C) { 94 func (s *SCPSuite) TestSCPCommand(c *gc.C) {
92 m := s.makeMachines(4, c, true) 95 m := s.makeMachines(4, c, true)
93 ch := coretesting.Charms.Dir("dummy") 96 ch := coretesting.Charms.Dir("dummy")
94 curl := charm.MustParseURL( 97 curl := charm.MustParseURL(
95 fmt.Sprintf("local:quantal/%s-%d", ch.Meta().Name, ch.Revision() ), 98 fmt.Sprintf("local:quantal/%s-%d", ch.Meta().Name, ch.Revision() ),
96 ) 99 )
97 bundleURL, err := url.Parse("http://bundles.testing.invalid/dummy-1") 100 bundleURL, err := url.Parse("http://bundles.testing.invalid/dummy-1")
(...skipping 14 matching lines...) Expand all
112 } 115 }
113 err = m[3].SetAddresses([]instance.Address{ipv6Addr}) 116 err = m[3].SetAddresses([]instance.Address{ipv6Addr})
114 c.Assert(err, gc.IsNil) 117 c.Assert(err, gc.IsNil)
115 srv = s.AddTestingService(c, "ipv6-svc", dummyCharm) 118 srv = s.AddTestingService(c, "ipv6-svc", dummyCharm)
116 s.addUnit(srv, m[3], c) 119 s.addUnit(srv, m[3], c)
117 120
118 for i, t := range scpTests { 121 for i, t := range scpTests {
119 c.Logf("test %d: %s -> %s\n", i, t.about, t.args) 122 c.Logf("test %d: %s -> %s\n", i, t.about, t.args)
120 ctx := coretesting.Context(c) 123 ctx := coretesting.Context(c)
121 scpcmd := &SCPCommand{} 124 scpcmd := &SCPCommand{}
122 scpcmd.proxy = t.proxy
123 125
124 err := scpcmd.Init(t.args) 126 err := scpcmd.Init(t.args)
125 c.Check(err, gc.IsNil) 127 c.Check(err, gc.IsNil)
126 err = scpcmd.Run(ctx) 128 err = scpcmd.Run(ctx)
127 if t.error != "" { 129 if t.error != "" {
128 c.Check(err, gc.ErrorMatches, t.error) 130 c.Check(err, gc.ErrorMatches, t.error)
129 c.Check(t.result, gc.Equals, "") 131 c.Check(t.result, gc.Equals, "")
130 } else { 132 } else {
131 c.Check(err, gc.IsNil) 133 c.Check(err, gc.IsNil)
132 // we suppress stdout from scp 134 // we suppress stdout from scp
133 c.Check(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "") 135 c.Check(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "")
134 c.Check(ctx.Stdout.(*bytes.Buffer).String(), gc.Equals, "") 136 c.Check(ctx.Stdout.(*bytes.Buffer).String(), gc.Equals, "")
135 data, err := ioutil.ReadFile(filepath.Join(s.bin, "scp.a rgs")) 137 data, err := ioutil.ReadFile(filepath.Join(s.bin, "scp.a rgs"))
136 c.Check(err, gc.IsNil) 138 c.Check(err, gc.IsNil)
137 c.Check(string(data), gc.Equals, t.result) 139 c.Check(string(data), gc.Equals, t.result)
138 } 140 }
139 } 141 }
140 } 142 }
OLDNEW
« no previous file with comments | « cmd/juju/scp.go ('k') | cmd/juju/ssh.go » ('j') | no next file with comments »

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