Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
46e02209
Commit
46e02209
authored
Aug 23, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Add UploadDir to the Communicator interface
parent
d6824a72
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
32 deletions
+60
-32
packer/communicator.go
packer/communicator.go
+5
-0
packer/communicator_mock.go
packer/communicator_mock.go
+41
-0
packer/communicator_mock_test.go
packer/communicator_mock_test.go
+13
-0
packer/communicator_test.go
packer/communicator_test.go
+1
-32
No files found.
packer/communicator.go
View file @
46e02209
...
...
@@ -59,6 +59,11 @@ type Communicator interface {
// it completes.
Upload
(
string
,
io
.
Reader
)
error
// UploadDir uploads the contents of a directory recursively to
// the remote path. It also takes an optional slice of paths to
// ignore when uploading.
UploadDir
(
string
,
string
,
[]
string
)
error
// Download downloads a file from the machine from the given remote path
// with the contents writing to the given writer. This method will
// block until it completes.
...
...
packer/communicator_mock.go
0 → 100644
View file @
46e02209
package
packer
import
(
"io"
)
// MockCommunicator is a valid Communicator implementation that can be
// used for tests.
type
MockCommunicator
struct
{
Stderr
io
.
Reader
Stdout
io
.
Reader
}
func
(
c
*
MockCommunicator
)
Start
(
rc
*
RemoteCmd
)
error
{
go
func
()
{
rc
.
Lock
()
defer
rc
.
Unlock
()
if
rc
.
Stdout
!=
nil
&&
c
.
Stdout
!=
nil
{
io
.
Copy
(
rc
.
Stdout
,
c
.
Stdout
)
}
if
rc
.
Stderr
!=
nil
&&
c
.
Stderr
!=
nil
{
io
.
Copy
(
rc
.
Stderr
,
c
.
Stderr
)
}
}()
return
nil
}
func
(
c
*
MockCommunicator
)
Upload
(
string
,
io
.
Reader
)
error
{
return
nil
}
func
(
c
*
MockCommunicator
)
UploadDir
(
string
,
string
,
[]
string
)
error
{
return
nil
}
func
(
c
*
MockCommunicator
)
Download
(
string
,
io
.
Writer
)
error
{
return
nil
}
packer/communicator_mock_test.go
0 → 100644
View file @
46e02209
package
packer
import
(
"testing"
)
func
TestMockCommunicator_impl
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
new
(
MockCommunicator
)
if
_
,
ok
:=
raw
.
(
Communicator
);
!
ok
{
t
.
Fatal
(
"should be a communicator"
)
}
}
packer/communicator_test.go
View file @
46e02209
...
...
@@ -2,42 +2,11 @@ package packer
import
(
"bytes"
"io"
"strings"
"testing"
"time"
)
type
TestCommunicator
struct
{
Stderr
io
.
Reader
Stdout
io
.
Reader
}
func
(
c
*
TestCommunicator
)
Start
(
rc
*
RemoteCmd
)
error
{
go
func
()
{
rc
.
Lock
()
defer
rc
.
Unlock
()
if
rc
.
Stdout
!=
nil
&&
c
.
Stdout
!=
nil
{
io
.
Copy
(
rc
.
Stdout
,
c
.
Stdout
)
}
if
rc
.
Stderr
!=
nil
&&
c
.
Stderr
!=
nil
{
io
.
Copy
(
rc
.
Stderr
,
c
.
Stderr
)
}
}()
return
nil
}
func
(
c
*
TestCommunicator
)
Upload
(
string
,
io
.
Reader
)
error
{
return
nil
}
func
(
c
*
TestCommunicator
)
Download
(
string
,
io
.
Writer
)
error
{
return
nil
}
func
TestRemoteCmd_StartWithUi
(
t
*
testing
.
T
)
{
data
:=
"hello
\n
world
\n
there"
...
...
@@ -46,7 +15,7 @@ func TestRemoteCmd_StartWithUi(t *testing.T) {
uiOutput
:=
new
(
bytes
.
Buffer
)
rcOutput
.
WriteString
(
data
)
testComm
:=
&
Test
Communicator
{
testComm
:=
&
Mock
Communicator
{
Stdout
:
rcOutput
,
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment