github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/utils_test.go (about) 1 package parser 2 3 import "testing" 4 5 func TestSafeGet(t *testing.T) { 6 t.Parallel() 7 8 expected := "foo" 9 10 test := make(map[string]interface{}, 1) 11 test["test"] = "foo" 12 13 actual := safeGetValue(test, "test") 14 15 if expected != actual { 16 t.Errorf("Expected %s, Got %s", expected, actual) 17 } 18 } 19 20 func TestSafeGetNil(t *testing.T) { 21 t.Parallel() 22 23 expected := "" 24 25 test := make(map[string]interface{}, 1) 26 test["test"] = nil 27 28 actual := safeGetValue(test, "test") 29 30 if expected != actual { 31 t.Errorf("Expected %s, Got %s", expected, actual) 32 } 33 } 34 35 func TestSafeGetInt(t *testing.T) { 36 t.Parallel() 37 38 expected := 1 39 40 test := make(map[string]interface{}, 1) 41 test["test"] = "1" 42 43 actual := safeGetInt(test, "test") 44 45 if expected != actual { 46 t.Errorf("Expected %d, Got %d", expected, actual) 47 } 48 49 if actual = safeGetInt(test, "foo"); actual != 0 { 50 t.Errorf("Expected 0, Got %d", actual) 51 } 52 } 53 54 func TestPrintHelp(t *testing.T) { 55 t.Parallel() 56 57 usage := "" 58 59 if !printHelp([]string{"ps", "--help"}, usage) { 60 t.Error("Expected true") 61 } 62 63 if !printHelp([]string{"ps", "-h"}, usage) { 64 t.Error("Expected true") 65 } 66 67 if printHelp([]string{"ps"}, usage) { 68 t.Error("Expected false") 69 } 70 71 if printHelp([]string{"ps", "--foo"}, usage) { 72 t.Error("Expected false") 73 } 74 }