Skip to content

Commit

Permalink
Add unit tests to improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bharathsreekanth authored Feb 13, 2025
1 parent e91d4c7 commit c8e75b6
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 11 deletions.
16 changes: 16 additions & 0 deletions inttest/pmax_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,22 @@ func TestGetISCSITargets(t *testing.T) {
fmt.Printf("Targets: %v\n", targets)
}

func TestGetNVMeTCPTargets(t *testing.T) {
if client == nil {
err := getClient()
if err != nil {
t.Error(err.Error())
return
}
}
targets, err := client.GetNVMeTCPTargets(context.TODO(), symmetrixID)
if err != nil {
t.Error("Error calling GetNVMeTCPTargets " + err.Error())
return
}
fmt.Printf("Targets: %v\n", targets)
}

func TestExpandVolume(t *testing.T) {
if client == nil {
err := getClient()
Expand Down
89 changes: 81 additions & 8 deletions migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,36 @@ func TestModifyMigrationSession(t *testing.T) {
expectedErr: nil,
},
"bad request": {
localSymID: "mock-local-sym-id",
storageGroupID: "mock-storage-group-id-2",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("bad request"),
},
"invalid array": {
localSymID: "invalid-array-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("the requested array (invalid-array-id) is ignored as it is not managed"),
},
}

for _, tc := range cases {
client, err := NewClientWithArgs(tc.server.URL, "", true, true, "")
if err != nil {
t.Fatal(err)
}
client.SetAllowedArrays([]string{"mock-local-sym-id"})
err = client.ModifyMigrationSession(context.TODO(), tc.localSymID, "mock-action", tc.storageGroupID)
if err != nil {
if tc.expectedErr.Error() != err.Error() {
t.Fatal(err)
}
}

tc.server.Close()
}
}
Expand Down Expand Up @@ -130,26 +140,35 @@ func TestCreateMigrationEnvironment(t *testing.T) {
expectedErr: nil,
},
"bad request": {
localSymID: "mock-local-sym-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("bad request"),
},
"invalid array": {
localSymID: "invalid-array-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("the requested array (invalid-array-id) is ignored as it is not managed"),
},
}

for _, tc := range cases {
client, err := NewClientWithArgs(tc.server.URL, "", true, true, "")
if err != nil {
t.Fatal(err)
}
client.SetAllowedArrays([]string{"mock-local-sym-id"})
_, err = client.CreateMigrationEnvironment(context.TODO(), tc.localSymID, tc.storageGroupID)
if err != nil {
if tc.expectedErr.Error() != err.Error() {
t.Fatal(err)
}
}

tc.server.Close()
}
}
Expand Down Expand Up @@ -178,26 +197,35 @@ func TestDeleteMigrationEnvironment(t *testing.T) {
expectedErr: nil,
},
"bad request": {
localSymID: "mock-local-sym-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("bad request"),
},
"invalid array": {
localSymID: "invalid-array-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("the requested array (invalid-array-id) is ignored as it is not managed"),
},
}

for _, tc := range cases {
client, err := NewClientWithArgs(tc.server.URL, "", true, true, "")
if err != nil {
t.Fatal(err)
}
client.SetAllowedArrays([]string{"mock-local-sym-id"})
err = client.DeleteMigrationEnvironment(context.TODO(), tc.localSymID, tc.remoteSymID)
if err != nil {
if tc.expectedErr.Error() != err.Error() {
t.Fatal(err)
}
}

tc.server.Close()
}
}
Expand Down Expand Up @@ -242,26 +270,35 @@ func TestCreateSGMigrationByID(t *testing.T) {
expectedErr: nil,
},
"bad request": {
localSymID: "mock-local-sym-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("bad request"),
},
"invalid array": {
localSymID: "invalid-array-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("the requested array (invalid-array-id) is ignored as it is not managed"),
},
}

for _, tc := range cases {
client, err := NewClientWithArgs(tc.server.URL, "", true, true, "")
if err != nil {
t.Fatal(err)
}
client.SetAllowedArrays([]string{"mock-local-sym-id"})
_, err = client.CreateSGMigration(context.TODO(), tc.localSymID, tc.remoteSymID, tc.storageGroupID)
if err != nil {
if tc.expectedErr.Error() != err.Error() {
t.Fatal(err)
}
}

tc.server.Close()
}
}
Expand Down Expand Up @@ -318,26 +355,35 @@ func TestMigrateStorageGroup(t *testing.T) {
expectedErr: nil,
},
"bad request": {
localSymID: "mock-local-sym-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("bad request"),
},
"invalid array": {
localSymID: "invalid-array-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("the requested array (invalid-array-id) is ignored as it is not managed"),
},
}

for _, tc := range cases {
client, err := NewClientWithArgs(tc.server.URL, "", true, true, "")
if err != nil {
t.Fatal(err)
}
client.SetAllowedArrays([]string{"mock-local-sym-id"})
_, err = client.MigrateStorageGroup(context.TODO(), tc.localSymID, tc.storageGroupID, tc.srpID, tc.serviceLevel, tc.thickVolumes)
if err != nil {
if tc.expectedErr.Error() != err.Error() {
t.Fatal(err)
}
}

tc.server.Close()
}
}
Expand Down Expand Up @@ -381,26 +427,35 @@ func TestGetStorageGroupMigrationByID(t *testing.T) {
expectedErr: nil,
},
"bad request": {
localSymID: "mock-local-sym-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("bad request"),
},
"invalid array": {
localSymID: "invalid-array-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("the requested array (invalid-array-id) is ignored as it is not managed"),
},
}

for _, tc := range cases {
client, err := NewClientWithArgs(tc.server.URL, "", true, true, "")
if err != nil {
t.Fatal(err)
}
client.SetAllowedArrays([]string{"mock-local-sym-id"})
_, err = client.GetStorageGroupMigrationByID(context.TODO(), tc.localSymID, tc.storageGroupID)
if err != nil {
if tc.expectedErr.Error() != err.Error() {
t.Fatal(err)
}
}

tc.server.Close()
}
}
Expand Down Expand Up @@ -442,26 +497,35 @@ func TestGetStorageGroupMigration(t *testing.T) {
expectedErr: nil,
},
"bad request": {
localSymID: "mock-local-sym-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("bad request"),
},
"invalid array": {
localSymID: "invalid-array-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("the requested array (invalid-array-id) is ignored as it is not managed"),
},
}

for _, tc := range cases {
client, err := NewClientWithArgs(tc.server.URL, "", true, true, "")
if err != nil {
t.Fatal(err)
}
client.SetAllowedArrays([]string{"mock-local-sym-id"})
_, err = client.GetStorageGroupMigration(context.TODO(), tc.localSymID)
if err != nil {
if tc.expectedErr.Error() != err.Error() {
t.Fatal(err)
}
}

tc.server.Close()
}
}
Expand Down Expand Up @@ -506,12 +570,21 @@ func TestGetMigrationEnvironment(t *testing.T) {
expectedErr: nil,
},
"bad request": {
localSymID: "mock-local-sym-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("bad request"),
},
"invalid array": {
localSymID: "invalid-array-id",
server: httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusBadRequest)
resp.Write([]byte(`{"message":"bad request","httpStatusCode":400,"errorCode":0}`))
})),
expectedErr: errors.New("the requested array (invalid-array-id) is ignored as it is not managed"),
},
}

for _, tc := range cases {
Expand All @@ -520,13 +593,13 @@ func TestGetMigrationEnvironment(t *testing.T) {
t.Fatal(err)
}

client.SetAllowedArrays([]string{"mock-local-sym-id"})
_, err = client.GetMigrationEnvironment(context.TODO(), tc.localSymID, tc.remoteSystemID)
if err != nil {
if tc.expectedErr.Error() != err.Error() {
t.Fatal(err)
}
}

tc.server.Close()
}
}
16 changes: 16 additions & 0 deletions mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ type inducedErrors struct {
GetPortError bool
GetSpecificPortError bool
GetPortISCSITargetError bool
GetPortNVMeTCPTargetError bool
GetPortGigEError bool
GetDirectorError bool
GetInitiatorError bool
Expand Down Expand Up @@ -365,6 +366,7 @@ func Reset() {
InducedErrors.GetPortError = false
InducedErrors.GetSpecificPortError = false
InducedErrors.GetPortISCSITargetError = false
InducedErrors.GetPortNVMeTCPTargetError = false
InducedErrors.GetPortGigEError = false
InducedErrors.GetDirectorError = false
InducedErrors.GetInitiatorError = false
Expand Down Expand Up @@ -686,6 +688,7 @@ func getRouter() http.Handler {
router.HandleFunc(PREFIX+"/system/version", HandleVersion)
router.HandleFunc(PREFIX+"/version", HandleVersion)
router.HandleFunc(PREFIXNOVERSION+"/version", HandleVersion)
router.HandleFunc(PREFIX+"/system/symmetrix/{id}/refresh", HandleSymmetrix)
router.HandleFunc("/", HandleNotFound)

// StorageGroup Snapshots
Expand Down Expand Up @@ -3292,6 +3295,10 @@ func handlePort(w http.ResponseWriter, r *http.Request) {
writeError(w, "Error retrieving GigE ports: induced error", http.StatusRequestTimeout)
return
}
if queryType[0] == "OSHostAndRDF" { // The first ?type=<value>
writeError(w, "Error retrieving OSHostAndRDF ports: induced error", http.StatusRequestTimeout)
return
}
}
}
if InducedErrors.GetPortISCSITargetError {
Expand All @@ -3303,6 +3310,15 @@ func handlePort(w http.ResponseWriter, r *http.Request) {
}
}
}
if InducedErrors.GetPortNVMeTCPTargetError {
queryType, ok := queryString["nvmetcp_endpoint"]
if ok {
if queryType[0] == "true" { // The first ?nvmetcp_endpoint=<value>
writeError(w, "Error retrieving NVMeTCP targets: induced error", http.StatusRequestTimeout)
return
}
}
}
// if we asked for a specific Port, return those details
if pID != "" {
if InducedErrors.GetSpecificPortError {
Expand Down
6 changes: 3 additions & 3 deletions system.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (c *Client) GetNVMeTCPTargets(ctx context.Context, symID string) ([]NVMeTCP
}

for _, d := range directors.DirectorIDs {
// Check if director is ISCSI
// Check if director is NVMETCP
// To do this, check if any ports have ports with GigE enabled
ports, err := c.GetPortList(ctx, symID, d, "type=OSHostAndRDF")
if err != nil {
Expand All @@ -391,8 +391,8 @@ func (c *Client) GetNVMeTCPTargets(ctx context.Context, symID string) ([]NVMeTCP
continue
}
if len(ports.SymmetrixPortKey) > 0 {
// This is a director with ISCSI port(s)
// Query for iscsi_targets
// This is a director with NVMeTCP port(s)
// Query for nvmetcp_endpoints
virtualPorts, err := c.GetPortList(ctx, symID, d, "nvmetcp_endpoint=true")
if err != nil {
return []NVMeTCPTarget{}, err
Expand Down
Loading

0 comments on commit c8e75b6

Please sign in to comment.