From 572b2cc75acf46f6cc5a0ef17c42c2938d9ebce8 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 | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 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..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") + } + }) + } +}