packer-cn/common/shell-local/communicator_test.go

47 lines
792 B
Go
Raw Normal View History

package shell_local
2015-06-19 18:27:44 -04:00
import (
"bytes"
"context"
2015-06-19 18:27:44 -04:00
"runtime"
"strings"
"testing"
2017-04-04 16:39:01 -04:00
"github.com/hashicorp/packer/packer"
2015-06-19 18:27:44 -04:00
)
func TestCommunicator_impl(t *testing.T) {
var _ packer.Communicator = new(Communicator)
}
func TestCommunicator(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("windows not supported for this test")
return
}
c := &Communicator{
2018-02-28 17:35:42 -05:00
ExecuteCommand: []string{"/bin/sh", "-c", "echo foo"},
2015-06-19 18:27:44 -04:00
}
var buf bytes.Buffer
cmd := &packer.RemoteCmd{
2018-02-28 17:35:42 -05:00
Stdout: &buf,
2015-06-19 18:27:44 -04:00
}
ctx := context.Background()
if err := c.Start(ctx, cmd); err != nil {
2015-06-19 18:27:44 -04:00
t.Fatalf("err: %s", err)
}
cmd.Wait()
if cmd.ExitStatus() != 0 {
t.Fatalf("err bad exit status: %d", cmd.ExitStatus())
2015-06-19 18:27:44 -04:00
}
if strings.TrimSpace(buf.String()) != "foo" {
t.Fatalf("bad: %s", buf.String())
}
}