github.com/dacamp/packer@v0.10.2/provisioner/shell-local/communicator_test.go (about)

     1  package shell
     2  
     3  import (
     4  	"bytes"
     5  	"runtime"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/mitchellh/packer/packer"
    10  )
    11  
    12  func TestCommunicator_impl(t *testing.T) {
    13  	var _ packer.Communicator = new(Communicator)
    14  }
    15  
    16  func TestCommunicator(t *testing.T) {
    17  	if runtime.GOOS == "windows" {
    18  		t.Skip("windows not supported for this test")
    19  		return
    20  	}
    21  
    22  	c := &Communicator{
    23  		ExecuteCommand: []string{"/bin/sh", "-c", "{{.Command}}"},
    24  	}
    25  
    26  	var buf bytes.Buffer
    27  	cmd := &packer.RemoteCmd{
    28  		Command: "echo foo",
    29  		Stdout:  &buf,
    30  	}
    31  
    32  	if err := c.Start(cmd); err != nil {
    33  		t.Fatalf("err: %s", err)
    34  	}
    35  
    36  	cmd.Wait()
    37  
    38  	if cmd.ExitStatus != 0 {
    39  		t.Fatalf("err bad exit status: %d", cmd.ExitStatus)
    40  	}
    41  
    42  	if strings.TrimSpace(buf.String()) != "foo" {
    43  		t.Fatalf("bad: %s", buf.String())
    44  	}
    45  }