github.com/aclaygray/packer@v1.3.2/common/shell-local/communicator_test.go (about)

     1  package shell_local
     2  
     3  import (
     4  	"bytes"
     5  	"runtime"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/hashicorp/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", "echo foo"},
    24  	}
    25  
    26  	var buf bytes.Buffer
    27  	cmd := &packer.RemoteCmd{
    28  		Stdout: &buf,
    29  	}
    30  
    31  	if err := c.Start(cmd); err != nil {
    32  		t.Fatalf("err: %s", err)
    33  	}
    34  
    35  	cmd.Wait()
    36  
    37  	if cmd.ExitStatus != 0 {
    38  		t.Fatalf("err bad exit status: %d", cmd.ExitStatus)
    39  	}
    40  
    41  	if strings.TrimSpace(buf.String()) != "foo" {
    42  		t.Fatalf("bad: %s", buf.String())
    43  	}
    44  }