From ac9aad9393fefcdf0f606aad79216e4293fe56a1 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Thu, 14 Mar 2024 13:42:36 -0400 Subject: [PATCH] add helpers test --- util/helpers_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 util/helpers_test.go diff --git a/util/helpers_test.go b/util/helpers_test.go new file mode 100644 index 000000000..df6d3b0a5 --- /dev/null +++ b/util/helpers_test.go @@ -0,0 +1,50 @@ +package util + +import ( + "errors" + "github.com/linode/linodego" + "testing" +) + +func TestIgnoreLinodeAPIError(t *testing.T) { + t.Parallel() + tests := []struct { + name string + err error + code int + shouldFilter bool + }{{ + name: "Not Linode API error", + err: errors.New("foo"), + code: 0, + shouldFilter: false, + }, { + name: "Ignore not found Linode API error", + err: linodego.Error{ + Response: nil, + Code: 400, + Message: "not found", + }, + code: 400, + shouldFilter: true, + }, { + name: "Don't ignore not found Linode API error", + err: linodego.Error{ + Response: nil, + Code: 400, + Message: "not found", + }, + code: 500, + shouldFilter: false, + }} + for _, tt := range tests { + testcase := tt + t.Run(testcase.name, func(t *testing.T) { + t.Parallel() + err := IgnoreLinodeAPIError(testcase.err, testcase.code) + if testcase.shouldFilter && err != nil { + t.Error("expected err but got nil") + } + }) + } +}