diff --git a/internal/pkg/util/interface.go b/internal/pkg/util/interface.go deleted file mode 100644 index 76e7d124..00000000 --- a/internal/pkg/util/interface.go +++ /dev/null @@ -1,43 +0,0 @@ -package util - -import ( - "reflect" - "strconv" - - "github.com/sirupsen/logrus" -) - -// InterfaceSlice converts an interface to an interface array -func InterfaceSlice(slice interface{}) []interface{} { - s := reflect.ValueOf(slice) - if s.Kind() != reflect.Slice { - logrus.Errorf("InterfaceSlice() given a non-slice type") - } - - ret := make([]interface{}, s.Len()) - - for i := 0; i < s.Len(); i++ { - ret[i] = s.Index(i).Interface() - } - - return ret -} - -// ParseBool returns result in bool format after parsing. -// It handles concrete bool/string types as well as any named type whose -// underlying kind is bool or string (e.g. type MyBool bool). -func ParseBool(value interface{}) bool { - if value == nil { - return false - } - v := reflect.ValueOf(value) - switch v.Kind() { - case reflect.Bool: - return v.Bool() - case reflect.String: - result, _ := strconv.ParseBool(v.String()) - return result - default: - return false - } -} diff --git a/internal/pkg/util/util_test.go b/internal/pkg/util/util_test.go index d76daf88..161e92d2 100644 --- a/internal/pkg/util/util_test.go +++ b/internal/pkg/util/util_test.go @@ -8,45 +8,6 @@ import ( "github.com/stakater/Reloader/internal/pkg/options" ) -// custom named types to verify reflect-based extraction -type myBool bool -type myString string - -func TestParseBool(t *testing.T) { - tests := []struct { - name string - input interface{} - want bool - }{ - // concrete bool - {"true bool", true, true}, - {"false bool", false, false}, - // concrete string - {"string true", "true", true}, - {"string 1", "1", true}, - {"string false", "false", false}, - {"string 0", "0", false}, - {"string invalid", "banana", false}, - // custom named bool kind - {"myBool true", myBool(true), true}, - {"myBool false", myBool(false), false}, - // custom named string kind - {"myString true", myString("true"), true}, - {"myString false", myString("false"), false}, - // nil and unsupported - {"nil", nil, false}, - {"int", 42, false}, - } - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - if got := ParseBool(tc.input); got != tc.want { - t.Errorf("ParseBool(%v) = %v, want %v", tc.input, got, tc.want) - } - }) - } -} - func TestConvertToEnvVarName(t *testing.T) { data := "www.stakater.com" envVar := ConvertToEnvVarName(data)