...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package gcp_test
16
17 import (
18 "fmt"
19 "testing"
20
21 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gcp"
22 "google.golang.org/api/googleapi"
23 )
24
25 func TestIsNotFoundError(t *testing.T) {
26 testCases := []struct {
27 Name string
28 Error error
29 ExpectedResult bool
30 }{
31 {"GCP NotFound", &googleapi.Error{Code: 404}, true},
32 {"GCP NotAuthorized", &googleapi.Error{Code: 403}, false},
33 {"Generic", fmt.Errorf("my generic error"), false},
34 }
35 for _, tc := range testCases {
36 t.Run(tc.Name, func(t *testing.T) {
37 result := gcp.IsNotFoundError(tc.Error)
38 if result != tc.ExpectedResult {
39 t.Errorf("unexpected result for gcp.IsNotFoundError('%v'): got '%v', want '%v'", tc.Error, result, tc.ExpectedResult)
40 }
41 })
42 }
43 }
44
45 func TestIsNotAuthorizedError(t *testing.T) {
46 testCases := []struct {
47 Name string
48 Error error
49 ExpectedResult bool
50 }{
51 {"GCP NotAuthorized", &googleapi.Error{Code: 403}, true},
52 {"GCP NotFound", &googleapi.Error{Code: 404}, false},
53 {"Generic", fmt.Errorf("my generic error"), false},
54 }
55 for _, tc := range testCases {
56 t.Run(tc.Name, func(t *testing.T) {
57 result := gcp.IsNotAuthorizedError(tc.Error)
58 if result != tc.ExpectedResult {
59 t.Errorf("unexpected result for gcp.IsNotAuthorizedError('%v'): got '%v', want '%v'", tc.Error, result, tc.ExpectedResult)
60 }
61 })
62 }
63 }
64
View as plain text