github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/packer/plugin/command_test.go (about)

     1  package plugin
     2  
     3  import (
     4  	"github.com/mitchellh/packer/packer"
     5  	"os/exec"
     6  	"testing"
     7  )
     8  
     9  type helperCommand byte
    10  
    11  func (helperCommand) Help() string {
    12  	return "2"
    13  }
    14  
    15  func (helperCommand) Run(packer.Environment, []string) int {
    16  	return 42
    17  }
    18  
    19  func (helperCommand) Synopsis() string {
    20  	return "1"
    21  }
    22  
    23  func TestCommand_NoExist(t *testing.T) {
    24  	c := NewClient(&ClientConfig{Cmd: exec.Command("i-should-not-exist")})
    25  	defer c.Kill()
    26  
    27  	_, err := c.Command()
    28  	if err == nil {
    29  		t.Fatal("should have error")
    30  	}
    31  }
    32  
    33  func TestCommand_Good(t *testing.T) {
    34  	c := NewClient(&ClientConfig{Cmd: helperProcess("command")})
    35  	defer c.Kill()
    36  
    37  	command, err := c.Command()
    38  	if err != nil {
    39  		t.Fatalf("should not have error: %s", err)
    40  	}
    41  
    42  	result := command.Synopsis()
    43  	if result != "1" {
    44  		t.Errorf("synopsis not correct: %s", result)
    45  	}
    46  
    47  	result = command.Help()
    48  	if result != "2" {
    49  		t.Errorf("help not correct: %s", result)
    50  	}
    51  }