Skip to content

Commit

Permalink
add helpers test
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyDumaine committed Mar 14, 2024
1 parent 123a51f commit 572b2cc
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions util/helpers_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
})
}
}

0 comments on commit 572b2cc

Please sign in to comment.