Skip to content

Commit 47dc06c

Browse files
author
Gustavo Bazan
authored
CLOUDP-185092: Add Unit tests for Atlas CLI file commonerrors/errors.go (#2571)
1 parent cbea179 commit 47dc06c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

internal/cli/atlas/commonerrors/errors.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ func Check(err error) error {
3232

3333
apiError, ok := admin.AsError(err)
3434
if ok {
35-
if apiError.GetErrorCode() == "TENANT_CLUSTER_UPDATE_UNSUPPORTED" {
35+
switch apiError.GetErrorCode() {
36+
case "TENANT_CLUSTER_UPDATE_UNSUPPORTED":
3637
return errClusterUnsupported
37-
}
38-
if apiError.GetErrorCode() == "GLOBAL_USER_OUTSIDE_SUBNET" {
38+
case "GLOBAL_USER_OUTSIDE_SUBNET":
3939
return errOutsideVPN
4040
}
4141
}

internal/cli/atlas/commonerrors/errors_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ package commonerrors
1919
import (
2020
"errors"
2121
"testing"
22+
23+
"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
24+
"go.mongodb.org/atlas-sdk/v20231115002/admin"
2225
)
2326

2427
func TestCheck(t *testing.T) {
2528
dummyErr := errors.New("dummy error")
2629

30+
skderr := &admin.GenericOpenAPIError{}
31+
skderr.SetModel(admin.ApiError{ErrorCode: pointer.Get("TENANT_CLUSTER_UPDATE_UNSUPPORTED")})
2732
testCases := []struct {
2833
name string
2934
err error
@@ -34,14 +39,11 @@ func TestCheck(t *testing.T) {
3439
err: nil,
3540
want: nil,
3641
},
37-
// TODO: Update the err object to test errors.go file
38-
/* {
42+
{
3943
name: "unsupported cluster update",
40-
err: &atlas.ErrorResponse{
41-
ErrorCode: "TENANT_CLUSTER_UPDATE_UNSUPPORTED",
42-
},
44+
err: skderr,
4345
want: errClusterUnsupported,
44-
},*/
46+
},
4547
{
4648
name: "arbitrary error",
4749
err: dummyErr,

0 commit comments

Comments
 (0)