github.com/rothwerx/packer@v0.9.0/post-processor/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/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  
    24  	var buf bytes.Buffer
    25  	cmd := &packer.RemoteCmd{
    26  		Command: "/bin/echo foo",
    27  		Stdout:  &buf,
    28  	}
    29  
    30  	if err := c.Start(cmd); err != nil {
    31  		t.Fatalf("err: %s", err)
    32  	}
    33  
    34  	cmd.Wait()
    35  
    36  	if cmd.ExitStatus != 0 {
    37  		t.Fatalf("err bad exit status: %d", cmd.ExitStatus)
    38  	}
    39  
    40  	if strings.TrimSpace(buf.String()) != "foo" {
    41  		t.Fatalf("bad: %s", buf.String())
    42  	}
    43  }