From d3fc91fdefee2cd41bf298002318a3942165553e Mon Sep 17 00:00:00 2001 From: warren-veerasingam Date: Tue, 22 May 2018 13:56:48 -0500 Subject: [PATCH] added test cases for command_test --- lib/command_test.go | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 lib/command_test.go diff --git a/lib/command_test.go b/lib/command_test.go new file mode 100644 index 00000000..ad357d83 --- /dev/null +++ b/lib/command_test.go @@ -0,0 +1,56 @@ +package lib_test + +import ( + "reflect" + "testing" + + "github.com/warren-veerasingam/terraform-switcher/lib" +) + +// TestNewCommand : pass value and check if returned value is a pointer +func TestNewCommand(t *testing.T) { + + testCmd := "terraform" + cmd := lib.NewCommand(testCmd) + + if reflect.ValueOf(cmd).Kind() == reflect.Ptr { + t.Logf("Value returned is a pointer %v [expected]", cmd) + } else { + t.Errorf("Value returned is not a pointer %v [expected", cmd) + } +} + +// TestPathList : check if bin path exist +func TestPathList(t *testing.T) { + + testCmd := "" + cmd := lib.NewCommand(testCmd) + listBin := cmd.PathList() + + if listBin == nil { + t.Error("No bin path found [unexpected]") + } else { + t.Logf("Found bin path [expected]") + } +} + +type Command struct { + name string +} + +// TestFind : check common "cd" command exist +// This is assuming that Windows and linux has the "cd" command +func TestFind(t *testing.T) { + + testCmd := "cd" + cmd := lib.NewCommand(testCmd) + + next := cmd.Find() + for path := next(); len(path) > 0; path = next() { + if path != "" { + t.Logf("Found installation path: %v [expected]\n", path) + } else { + t.Errorf("Unable to find '%v' command in this operating system [unexpected]", testCmd) + } + } +}