diff --git a/util/helpers_test.go b/util/helpers_test.go new file mode 100644 index 000000000..1be231969 --- /dev/null +++ b/util/helpers_test.go @@ -0,0 +1,51 @@ +package util + +import ( + "errors" + "testing" + + "github.com/linode/linodego" +) + +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") + } + }) + } +}