Skip to content

Commit

Permalink
add some more functionality to MockCommunicator
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Mar 20, 2018
1 parent 9b4b5f2 commit 2954d98
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions communicator/communicator_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type MockCommunicator struct {
Uploads map[string]string
UploadScripts map[string]string
UploadDirs map[string]string
CommandFunc func(*remote.Cmd) error
DisconnectFunc func() error
ConnTimeout time.Duration
}

// Connect implementation of communicator.Communicator interface
Expand All @@ -27,11 +30,17 @@ func (c *MockCommunicator) Connect(o terraform.UIOutput) error {

// Disconnect implementation of communicator.Communicator interface
func (c *MockCommunicator) Disconnect() error {
if c.DisconnectFunc != nil {
return c.DisconnectFunc()
}
return nil
}

// Timeout implementation of communicator.Communicator interface
func (c *MockCommunicator) Timeout() time.Duration {
if c.ConnTimeout != 0 {
return c.ConnTimeout
}
return time.Duration(5 * time.Second)
}

Expand All @@ -44,6 +53,10 @@ func (c *MockCommunicator) ScriptPath() string {
func (c *MockCommunicator) Start(r *remote.Cmd) error {
r.Init()

if c.CommandFunc != nil {
return c.CommandFunc(r)
}

if !c.Commands[r.Command] {
return fmt.Errorf("Command not found!")
}
Expand Down

0 comments on commit 2954d98

Please sign in to comment.