Skip to content

Commit

Permalink
CLOUDP-185092: Add Unit tests for Atlas CLI file commonerrors/errors.…
Browse files Browse the repository at this point in the history
…go (#2571)
  • Loading branch information
gssbzn authored Jan 26, 2024
1 parent cbea179 commit 47dc06c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions internal/cli/atlas/commonerrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func Check(err error) error {

apiError, ok := admin.AsError(err)
if ok {
if apiError.GetErrorCode() == "TENANT_CLUSTER_UPDATE_UNSUPPORTED" {
switch apiError.GetErrorCode() {
case "TENANT_CLUSTER_UPDATE_UNSUPPORTED":
return errClusterUnsupported
}
if apiError.GetErrorCode() == "GLOBAL_USER_OUTSIDE_SUBNET" {
case "GLOBAL_USER_OUTSIDE_SUBNET":
return errOutsideVPN
}
}
Expand Down
14 changes: 8 additions & 6 deletions internal/cli/atlas/commonerrors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ package commonerrors
import (
"errors"
"testing"

"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
"go.mongodb.org/atlas-sdk/v20231115002/admin"
)

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

skderr := &admin.GenericOpenAPIError{}
skderr.SetModel(admin.ApiError{ErrorCode: pointer.Get("TENANT_CLUSTER_UPDATE_UNSUPPORTED")})
testCases := []struct {
name string
err error
Expand All @@ -34,14 +39,11 @@ func TestCheck(t *testing.T) {
err: nil,
want: nil,
},
// TODO: Update the err object to test errors.go file
/* {
{
name: "unsupported cluster update",
err: &atlas.ErrorResponse{
ErrorCode: "TENANT_CLUSTER_UPDATE_UNSUPPORTED",
},
err: skderr,
want: errClusterUnsupported,
},*/
},
{
name: "arbitrary error",
err: dummyErr,
Expand Down

0 comments on commit 47dc06c

Please sign in to comment.