daily tests

This commit is contained in:
gezimbll
2022-10-18 10:49:02 -04:00
committed by Dan Christian Bogos
parent e488176034
commit b8682b9772
4 changed files with 178 additions and 1 deletions

View File

@@ -425,7 +425,6 @@ func TestFlagsWithParamsClone(t *testing.T) {
}
}
// my test
func TestStringMapFieldAsInterfaceNotNil(t *testing.T) {
sm := StringMap{}
fldPath := []string{"first", "second"}

View File

@@ -1889,3 +1889,106 @@ func TestIfaceAsTFloat64(t *testing.T) {
t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err)
}
}
func TestIfaceAsTInt(t *testing.T) {
eInt := 3
val := interface{}(3)
if intConvert, err := IfaceAsTInt(val); err != nil {
t.Error(err)
} else if intConvert != eInt {
t.Errorf("received %+v", intConvert)
}
val = interface{}(time.Duration(3))
if intConvert, err := IfaceAsTInt(val); err != nil {
t.Error(err)
} else if intConvert != eInt {
t.Errorf("received %+v ", intConvert)
}
val = interface{}(int32(3))
if intConvert, err := IfaceAsTInt(val); err != nil {
t.Error(err)
} else if intConvert != eInt {
t.Errorf("received %+v ", intConvert)
}
val = interface{}(int64(3))
if intConvert, err := IfaceAsTInt(val); err != nil {
t.Error(err)
} else if intConvert != eInt {
t.Errorf("received %+v", intConvert)
}
val = interface{}(3.122)
if intConvert, err := IfaceAsTInt(val); err != nil {
t.Error(err)
} else if intConvert != eInt {
t.Errorf("received %+v", intConvert)
}
val = interface{}(float32(3.11))
if intConvert, err := IfaceAsTInt(val); err != nil {
t.Error(err)
} else if intConvert != eInt {
t.Errorf("received %+v", intConvert)
}
val = interface{}("3")
if intConvert, err := IfaceAsTInt(val); err != nil {
t.Error(err)
} else if intConvert != eInt {
t.Errorf("received %+v", intConvert)
}
val = interface{}(nil)
if _, err := IfaceAsTInt(val); err == nil {
t.Error("expecting error")
}
}
func TestIfaceStringInterface(t *testing.T) {
s := ""
if strItem := StringToInterface(s); strItem != s {
t.Error("Return empty")
}
s = "3"
if _, ok := StringToInterface(s).(int64); !ok {
t.Errorf("received type %T", s)
}
s = "false"
if _, ok := StringToInterface(s).(bool); !ok {
t.Errorf("received type %T ", s)
}
s = "4.566"
if _, ok := StringToInterface(s).(float64); !ok {
t.Errorf("received type %T", s)
}
s = "*daily"
if _, ok := StringToInterface(s).(time.Time); !ok {
t.Errorf("received %T", s)
}
s = "3s"
if _, ok := StringToInterface(s).(time.Duration); !ok {
t.Errorf("received type %T", s)
}
s = "A string"
if _, ok := StringToInterface(s).(string); !ok {
t.Error("Should return string")
}
}

View File

@@ -265,3 +265,36 @@ func TestStringSetJoin(t *testing.T) {
t.Errorf("Expected %+v, received %+v", ToJSON(expected), ToJSON(rcv))
}
}
func TestStringFieldAsInterface(t *testing.T) {
var s StringSet
fldPath := []string{"test1", "test2", "test3"}
if val, _ := s.FieldAsInterface(fldPath); val != nil {
t.Error("expected error")
}
fldPath = []string{"test1"}
s = StringSet{
"test2": struct{}{},
}
if val, _ := s.FieldAsInterface(fldPath); val != nil {
t.Errorf("expected error")
}
fldPath = []string{"test2"}
if val, err := s.FieldAsInterface(fldPath); err != nil {
t.Errorf("expected %v", val)
}
}
func TestStringFieldAsString(t *testing.T) {
s := StringSet{}
fldPath := []string{"test1"}
if _, err := s.FieldAsString(fldPath); err == nil {
t.Error("expected error")
}
exp := "{}"
s["test1"] = struct{}{}
if _, err := s.FieldAsString(fldPath); err != nil {
t.Errorf("expected %v got error", exp)
}
}

View File

@@ -289,3 +289,45 @@ func TestValueFormulaCover(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", expected, received)
}
}
func TestValueFieldAsInterface(t *testing.T) {
vf := &ValueFormula{}
fldPath := make([]string, 0)
if val, _ := vf.FieldAsInterface(fldPath); val != nil {
t.Errorf("expected error")
}
fldPath = []string{"test1"}
vf = &ValueFormula{
Method: "Method",
Params: map[string]interface{}{},
Static: 22,
}
if val, _ := vf.FieldAsInterface(fldPath); val != nil {
t.Error("expected error")
}
fldPath = []string{"Method"}
if _, err := vf.FieldAsInterface(fldPath); err != nil {
t.Errorf("expected %v ", vf.Method)
}
fldPath = []string{"Method", "second"}
if val, _ := vf.FieldAsInterface(fldPath); val != nil {
t.Error("expected error")
}
fldPath = []string{"Static"}
if _, err := vf.FieldAsInterface(fldPath); err != nil {
t.Errorf("expected %v", vf.Static)
}
fldPath = []string{"Static", "second"}
if val, _ := vf.FieldAsInterface(fldPath); val != nil {
t.Error("expected error")
}
fldPath = []string{"Params"}
if _, err := vf.FieldAsInterface(fldPath); err != nil {
t.Errorf("expected %v", vf.Params)
}
fldPath = []string{"Params", "second"}
if val, _ := vf.FieldAsInterface(fldPath); val != nil {
t.Error("expected error")
}
}