From 0e9da38af4b4f5aa9a84c9e580dc40a0f81c4efa Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Sat, 14 Jan 2023 08:59:59 +0100 Subject: [PATCH] improve error handling in tests Signed-off-by: Florian Lehner --- f_basic_test.go | 4 ++-- f_bpf_test.go | 4 ++-- f_cgroup_test.go | 4 ++-- f_flow_test.go | 4 ++-- f_flower_test.go | 4 ++-- f_fw_test.go | 4 ++-- f_matchall_test.go | 4 ++-- f_route4_test.go | 4 ++-- f_rsvp_test.go | 4 ++-- f_tcindex_test.go | 4 ++-- f_u32_test.go | 4 ++-- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/f_basic_test.go b/f_basic_test.go index 8aaea0d..f8bb11a 100644 --- a/f_basic_test.go +++ b/f_basic_test.go @@ -48,7 +48,7 @@ func TestBasic(t *testing.T) { t.Run(name, func(t *testing.T) { data, err1 := marshalBasic(&testcase.val) if err1 != nil { - if testcase.err1 != nil && testcase.err1.Error() == err1.Error() { + if errors.Is(err1, testcase.err1) { return } t.Fatalf("Unexpected error: %v", err1) @@ -56,7 +56,7 @@ func TestBasic(t *testing.T) { val := Basic{} err2 := unmarshalBasic(data, &val) if err2 != nil { - if testcase.err2 != nil && testcase.err2.Error() == err2.Error() { + if errors.Is(err2, testcase.err2) { return } t.Fatalf("Unexpected error: %v", err2) diff --git a/f_bpf_test.go b/f_bpf_test.go index b3af504..f78bb14 100644 --- a/f_bpf_test.go +++ b/f_bpf_test.go @@ -53,7 +53,7 @@ func TestBpf(t *testing.T) { t.Run(name, func(t *testing.T) { data, err1 := marshalBpf(&testcase.val) if err1 != nil { - if testcase.err1 != nil && testcase.err1.Error() == err1.Error() { + if errors.Is(err1, testcase.err1) { return } t.Fatalf("Unexpected error: %v", err1) @@ -61,7 +61,7 @@ func TestBpf(t *testing.T) { val := Bpf{} err2 := unmarshalBpf(data, &val) if err2 != nil { - if testcase.err2 != nil && testcase.err2.Error() == err2.Error() { + if errors.Is(err2, testcase.err2) { return } t.Fatalf("Unexpected error: %v", err2) diff --git a/f_cgroup_test.go b/f_cgroup_test.go index ecca398..22f594c 100644 --- a/f_cgroup_test.go +++ b/f_cgroup_test.go @@ -44,7 +44,7 @@ func TestCgroup(t *testing.T) { t.Run(name, func(t *testing.T) { data, err1 := marshalCgroup(&testcase.val) if err1 != nil { - if testcase.err1 != nil && testcase.err1.Error() == err1.Error() { + if errors.Is(err1, testcase.err1) { return } t.Fatalf("Unexpected error: %v", err1) @@ -52,7 +52,7 @@ func TestCgroup(t *testing.T) { val := Cgroup{} err2 := unmarshalCgroup(data, &val) if err2 != nil { - if testcase.err2 != nil && testcase.err2.Error() == err2.Error() { + if errors.Is(err2, testcase.err2) { return } t.Fatalf("Unexpected error: %v", err2) diff --git a/f_flow_test.go b/f_flow_test.go index 2a2be42..96ab853 100644 --- a/f_flow_test.go +++ b/f_flow_test.go @@ -49,7 +49,7 @@ func TestFlow(t *testing.T) { t.Run(name, func(t *testing.T) { data, err1 := marshalFlow(&testcase.val) if err1 != nil { - if testcase.err1 != nil && testcase.err1.Error() == err1.Error() { + if errors.Is(err1, testcase.err1) { return } t.Fatalf("Unexpected error: %v", err1) @@ -57,7 +57,7 @@ func TestFlow(t *testing.T) { val := Flow{} err2 := unmarshalFlow(data, &val) if err2 != nil { - if testcase.err2 != nil && testcase.err2.Error() == err2.Error() { + if errors.Is(err2, testcase.err2) { return } t.Fatalf("Unexpected error: %v", err2) diff --git a/f_flower_test.go b/f_flower_test.go index 7fc1b58..ccf44ce 100644 --- a/f_flower_test.go +++ b/f_flower_test.go @@ -125,7 +125,7 @@ func TestFlower(t *testing.T) { t.Run(name, func(t *testing.T) { data, err1 := marshalFlower(&testcase.val) if err1 != nil { - if testcase.err1 != nil && testcase.err1.Error() == err1.Error() { + if errors.Is(err1, testcase.err1) { return } t.Fatalf("Unexpected error: %v", err1) @@ -136,7 +136,7 @@ func TestFlower(t *testing.T) { val := Flower{} err2 := unmarshalFlower(newData, &val) if err2 != nil { - if testcase.err2 != nil && testcase.err2.Error() == err2.Error() { + if errors.Is(err2, testcase.err2) { return } t.Fatalf("Unexpected error: %v", err2) diff --git a/f_fw_test.go b/f_fw_test.go index 7651a6d..714ed34 100644 --- a/f_fw_test.go +++ b/f_fw_test.go @@ -30,7 +30,7 @@ func TestFw(t *testing.T) { t.Run(name, func(t *testing.T) { data, err1 := marshalFw(&testcase.val) if err1 != nil { - if testcase.err1 != nil && testcase.err1.Error() == err1.Error() { + if errors.Is(err1, testcase.err1) { return } t.Fatalf("Unexpected error: %v", err1) @@ -38,7 +38,7 @@ func TestFw(t *testing.T) { val := Fw{} err2 := unmarshalFw(data, &val) if err2 != nil { - if testcase.err2 != nil && testcase.err2.Error() == err2.Error() { + if errors.Is(err2, testcase.err2) { return } t.Fatalf("Unexpected error: %v", err2) diff --git a/f_matchall_test.go b/f_matchall_test.go index ea9ad37..2e6d289 100644 --- a/f_matchall_test.go +++ b/f_matchall_test.go @@ -25,7 +25,7 @@ func TestMatchall(t *testing.T) { t.Run(name, func(t *testing.T) { data, err1 := marshalMatchall(&testcase.val) if err1 != nil { - if testcase.err1 != nil && errors.Is(err1, testcase.err1) { + if errors.Is(err1, testcase.err1) { return } t.Fatalf("Unexpected error: %v", err1) @@ -34,7 +34,7 @@ func TestMatchall(t *testing.T) { val := Matchall{} err2 := unmarshalMatchall(newData, &val) if err2 != nil { - if testcase.err2 != nil && errors.Is(err2, testcase.err2) { + if errors.Is(err2, testcase.err2) { return } t.Fatalf("Unexpected error: %v", err2) diff --git a/f_route4_test.go b/f_route4_test.go index 6db6c51..6804c0a 100644 --- a/f_route4_test.go +++ b/f_route4_test.go @@ -25,7 +25,7 @@ func TestRoute4(t *testing.T) { t.Run(name, func(t *testing.T) { data, err1 := marshalRoute4(&testcase.val) if err1 != nil { - if testcase.err1 != nil && testcase.err1.Error() == err1.Error() { + if errors.Is(err1, testcase.err1) { return } t.Fatalf("Unexpected error: %v", err1) @@ -33,7 +33,7 @@ func TestRoute4(t *testing.T) { val := Route4{} err2 := unmarshalRoute4(data, &val) if err2 != nil { - if testcase.err2 != nil && testcase.err2.Error() == err2.Error() { + if errors.Is(err2, testcase.err2) { return } t.Fatalf("Unexpected error: %v", err2) diff --git a/f_rsvp_test.go b/f_rsvp_test.go index 1f98199..e3a19e7 100644 --- a/f_rsvp_test.go +++ b/f_rsvp_test.go @@ -26,7 +26,7 @@ func TestRsvp(t *testing.T) { t.Run(name, func(t *testing.T) { data, err1 := marshalRsvp(&testcase.val) if err1 != nil { - if testcase.err1 != nil && testcase.err1.Error() == err1.Error() { + if errors.Is(err1, testcase.err1) { return } t.Fatalf("Unexpected error: %v", err1) @@ -34,7 +34,7 @@ func TestRsvp(t *testing.T) { val := Rsvp{} err2 := unmarshalRsvp(data, &val) if err2 != nil { - if testcase.err2 != nil && testcase.err2.Error() == err2.Error() { + if errors.Is(err2, testcase.err2) { return } t.Fatalf("Unexpected error: %v", err2) diff --git a/f_tcindex_test.go b/f_tcindex_test.go index e4cff23..ea2e617 100644 --- a/f_tcindex_test.go +++ b/f_tcindex_test.go @@ -29,7 +29,7 @@ func TestTcIndex(t *testing.T) { t.Run(name, func(t *testing.T) { data, err1 := marshalTcIndex(&testcase.val) if err1 != nil { - if testcase.err1 != nil && errors.Is(err1, testcase.err1) { + if errors.Is(err1, testcase.err1) { return } t.Fatalf("Unexpected error: %v", err1) @@ -37,7 +37,7 @@ func TestTcIndex(t *testing.T) { val := TcIndex{} err2 := unmarshalTcIndex(data, &val) if err2 != nil { - if testcase.err2 != nil && errors.Is(err2, testcase.err2) { + if errors.Is(err2, testcase.err2) { return } t.Fatalf("Unexpected error: %v", err2) diff --git a/f_u32_test.go b/f_u32_test.go index 67555f0..78ba5c0 100644 --- a/f_u32_test.go +++ b/f_u32_test.go @@ -66,7 +66,7 @@ func TestU32(t *testing.T) { t.Run(name, func(t *testing.T) { data, err1 := marshalU32(&testcase.val) if err1 != nil { - if testcase.err1 != nil && errors.Is(err1, testcase.err1) { + if errors.Is(err1, testcase.err1) { return } t.Fatalf("Unexpected error: %v", err1) @@ -75,7 +75,7 @@ func TestU32(t *testing.T) { val := U32{} err2 := unmarshalU32(newData, &val) if err2 != nil { - if testcase.err2 != nil && errors.Is(err2, testcase.err2) { + if errors.Is(err2, testcase.err2) { return } t.Fatalf("Unexpected error: %v", err2)