Remove unnecessary error check

This commit is contained in:
NikolasPetriti
2023-06-16 08:53:49 +02:00
committed by Dan Christian Bogos
parent 75afa538ee
commit 0d1e468fa0
2 changed files with 3 additions and 45 deletions

View File

@@ -547,12 +547,7 @@ func Sum(items ...any) (sum any, err error) {
}
}
case int:
// need explicit conversion for int
if firstItmVal, err := IfaceAsInt64(dt); err != nil {
return nil, err
} else {
sum = firstItmVal
}
sum = int64(dt)
for _, item := range items[1:] {
if itmVal, err := IfaceAsInt64(item); err != nil {
return nil, err
@@ -609,12 +604,7 @@ func Difference(items ...any) (diff any, err error) {
}
}
case int:
// need explicit conversion for int
if firstItmVal, err := IfaceAsInt64(dt); err != nil {
return nil, err
} else {
diff = firstItmVal
}
diff = int64(dt)
for _, item := range items[1:] {
if itmVal, err := IfaceAsInt64(item); err != nil {
return nil, err

View File

@@ -132,30 +132,9 @@ func TestReflectFieldInterface(t *testing.T) {
})
}
}
type MyInterface interface {
MyMethod() string
}
type MyStruct struct {
Value MyInterface
}
type MyType string
func (mt MyType) MyMethod() string {
return "string(mt)"
}
var s MyType
func TestReflectFieldAsString(t *testing.T) {
type Iface interface{}
var a map[string]any = map[string]any{"test": "test1"}
type args struct {
intf any
fldName string
@@ -176,26 +155,15 @@ func TestReflectFieldAsString(t *testing.T) {
args: args{struct{ Test bool }{Test: false}, "Test", ""},
want: "",
},
{
name: "interface",
args: args{a, "test", ""},
want: "test1",
},
}
for i, tt := range tests {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rcv, err := ReflectFieldAsString(tt.args.intf, tt.args.fldName, tt.args.extraFieldsLabel)
if i == len(tests) - 1 {
if err != nil {
t.Fatal("was not expecting an error", err)
}
} else {
if err == nil {
t.Fatal("was expecting an error")
}
}
if rcv != tt.want {
t.Errorf("reciving %v, expected %v", rcv, tt.want)