github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/pkg/inspector/check/executable_test.go (about)

     1  package check
     2  
     3  import "testing"
     4  
     5  func TestExecutableInPathExists(t *testing.T) {
     6  	c := ExecutableInPathCheck{
     7  		Name: "ls",
     8  	}
     9  	ok, err := c.Check()
    10  	if err != nil {
    11  		t.Errorf("Unexpected error: %v", err)
    12  	}
    13  	if !ok {
    14  		t.Errorf("Expected ls to be in the path")
    15  	}
    16  }
    17  
    18  func TestExecutableMissingFromPath(t *testing.T) {
    19  	c := ExecutableInPathCheck{
    20  		Name: "non-existent-binary",
    21  	}
    22  	ok, err := c.Check()
    23  	if err != nil {
    24  		t.Errorf("Unexpected error when running binary dependency check: %v", err)
    25  	}
    26  	if ok {
    27  		t.Error("check returned OK for a binary that does not exist")
    28  	}
    29  }
    30  
    31  func TestExecutableInPathBadName(t *testing.T) {
    32  	tests := []struct {
    33  		name string
    34  	}{
    35  		{name: "echo; exit 0"},
    36  		{name: "1234"},
    37  		{name: "hello$?"},
    38  		{name: "!echo"},
    39  	}
    40  	for _, test := range tests {
    41  		c := ExecutableInPathCheck{
    42  			Name: test.name,
    43  		}
    44  		ok, err := c.Check()
    45  		if err == nil {
    46  			t.Errorf("expected an error but didn't get one")
    47  		}
    48  		if ok {
    49  			t.Errorf("check returned OK for an invalid binary name")
    50  		}
    51  	}
    52  
    53  }