github.com/grantbow/fit@v0.7.1-0.20220916164603-1f7c88ac81e6/fitapp/utils_test.go (about) 1 package fitapp 2 3 import ( 4 "testing" 5 ) 6 7 func TestGetArgument(t *testing.T) { 8 args := argumentList{"foo", "--github", "bar"} 9 if "bar" != args.GetArgument("--github", "") { 10 t.Error("GetArgument should return the string value") 11 } 12 args = argumentList{"foo", "other", "bar"} 13 if "" != args.GetArgument("--github", "") { 14 t.Error("GetArgument should return the default value") 15 } 16 } 17 18 func TestGetAndRemoveArguments(t *testing.T) { 19 Args := argumentList{"--tag", "bar"} 20 argout, argVals := Args.GetAndRemoveArguments([]string{"--tag", "--status", "--priority", "--milestone", "--identifier"}) 21 22 if len(argout) != 0 { 23 t.Error("--tag not removed from Args") 24 } 25 if argVals[0] != "bar" { 26 t.Errorf("--tag value not set, expected %s got %s", Args[0], argVals[0]) 27 } 28 } 29 30 func TestSkipRootCheck(t *testing.T) { 31 list := []string{} 32 if !SkipRootCheck(&list) { 33 t.Error("SkipRootCheck 0 should return true") 34 } 35 list = []string{"bin"} 36 if !SkipRootCheck(&list) { 37 t.Error("SkipRootCheck 1 should return true") 38 } 39 list = []string{"bin", "help"} 40 if !SkipRootCheck(&list) { 41 t.Error("SkipRootCheck 2 help should return true") 42 } 43 list = []string{"bin", "nohelp"} 44 if SkipRootCheck(&list) { 45 t.Error("SkipRootCheck 2 nohelp should return false") 46 } 47 list = []string{"bin", "ver", "--help"} 48 if !SkipRootCheck(&list) { 49 t.Error("SkipRootCheck 3 --help should return true") 50 } 51 }