-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32c3df0
commit b497ecf
Showing
2 changed files
with
269 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,268 @@ | ||
// Copyright © 2023 Dell Inc. or its subsidiaries. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package goscaleio | ||
|
||
import ( | ||
"errors" | ||
"math" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
types "github.com/dell/goscaleio/types/v1" | ||
) | ||
|
||
var ( | ||
ID string | ||
errFs error | ||
) | ||
|
||
func TestCreateFaultSet(t *testing.T) { | ||
type testCase struct { | ||
fs *types.FaultSetParam | ||
expected error | ||
} | ||
cases := []testCase{ | ||
{ | ||
fs: &types.FaultSetParam{ | ||
Name: "testFaultSet", | ||
ProtectionDomainID: "202a046600000000", | ||
}, | ||
expected: nil, | ||
}, | ||
{ | ||
fs: &types.FaultSetParam{ | ||
Name: "testFaultSet", | ||
ProtectionDomainID: "202a0466000000", | ||
}, | ||
expected: errors.New("Invalid Protection Domain. Please try again with the correct ID or name."), | ||
}, | ||
} | ||
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
})) | ||
defer svr.Close() | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
t.Run("", func(ts *testing.T) { | ||
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
p := NewProtectionDomain(client) | ||
|
||
ID, errFs = p.CreateFaultSet(tc.fs) | ||
if errFs != nil { | ||
if tc.expected == nil { | ||
t.Errorf("Creating fault set did not work as expected, \n\tgot: %s \n\twant: %v", errFs, tc.expected) | ||
} else { | ||
if errFs.Error() != tc.expected.Error() { | ||
t.Errorf("Creating fault set did not work as expected, \n\tgot: %s \n\twant: %s", errFs, tc.expected) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestGetFaultByID(t *testing.T) { | ||
type testCase struct { | ||
id string | ||
expected error | ||
} | ||
cases := []testCase{ | ||
{ | ||
id: ID, | ||
expected: nil, | ||
}, | ||
{ | ||
id: "1234", | ||
expected: errors.New("Invalid Fault Set. Please try again with the correct ID or name."), | ||
}, | ||
} | ||
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
})) | ||
defer svr.Close() | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
t.Run("", func(ts *testing.T) { | ||
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
s := System{ | ||
client: client, | ||
} | ||
_, err2 := s.GetFaultSetByID(tc.id) | ||
if err2 != nil { | ||
if tc.expected == nil { | ||
t.Errorf("Fetching fault set did not work as expected, \n\tgot: %s \n\twant: %v", err2, tc.expected) | ||
} else { | ||
if err2.Error() != tc.expected.Error() { | ||
t.Errorf("Fetching fault set did not work as expected, \n\tgot: %s \n\twant: %s", err2, tc.expected) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestModifyFaultSetName(t *testing.T) { | ||
type testCase struct { | ||
name string | ||
id string | ||
expected error | ||
} | ||
cases := []testCase{ | ||
{ | ||
|
||
id: ID, | ||
name: "renameFaultSet", | ||
expected: nil, | ||
}, | ||
{ | ||
id: "1234", | ||
name: "renameFaultSet", | ||
expected: errors.New("Invalid Fault Set. Please try again with the correct ID or name."), | ||
}, | ||
} | ||
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
})) | ||
defer svr.Close() | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
t.Run("", func(ts *testing.T) { | ||
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
p := ProtectionDomain{ | ||
client: client, | ||
} | ||
err2 := p.ModifyFaultSetName(tc.id, tc.name) | ||
if err2 != nil { | ||
if tc.expected == nil { | ||
t.Errorf("Modifying fault set did not work as expected, \n\tgot: %s \n\twant: %v", err2, tc.expected) | ||
} else { | ||
if err2.Error() != tc.expected.Error() { | ||
t.Errorf("Modifying fault set did not work as expected, \n\tgot: %s \n\twant: %s", err2, tc.expected) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestModifyFaultPerfProfile(t *testing.T) { | ||
type testCase struct { | ||
perfProfile string | ||
id string | ||
expected error | ||
} | ||
cases := []testCase{ | ||
{ | ||
|
||
id: ID, | ||
perfProfile: "Compact", | ||
expected: nil, | ||
}, | ||
{ | ||
|
||
id: ID, | ||
perfProfile: "HighPerformance", | ||
expected: nil, | ||
}, | ||
{ | ||
|
||
id: ID, | ||
perfProfile: "Invalid", | ||
expected: errors.New("perfProfile should get one of the following values: Compact, HighPerformance, but its value is Invalid."), | ||
}, | ||
} | ||
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
})) | ||
defer svr.Close() | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
t.Run("", func(ts *testing.T) { | ||
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
p := ProtectionDomain{ | ||
client: client, | ||
} | ||
err2 := p.ModifyFaultSetPerfProfile(tc.id, tc.perfProfile) | ||
if err2 != nil { | ||
if tc.expected == nil { | ||
t.Errorf("Modifying fault set did not work as expected, \n\tgot: %s \n\twant: %v", err2, tc.expected) | ||
} else { | ||
if err2.Error() != tc.expected.Error() { | ||
t.Errorf("Modifying fault set did not work as expected, \n\tgot: %s \n\twant: %s", err2, tc.expected) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestDeleteFaultSet(t *testing.T) { | ||
type testCase struct { | ||
id string | ||
expected error | ||
} | ||
cases := []testCase{ | ||
{ | ||
id: ID, | ||
expected: nil, | ||
}, | ||
{ | ||
id: "1234", | ||
expected: errors.New("Invalid Fault Set. Please try again with the correct ID or name."), | ||
}, | ||
} | ||
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
})) | ||
defer svr.Close() | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
t.Run("", func(ts *testing.T) { | ||
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
p := ProtectionDomain{ | ||
client: client, | ||
} | ||
err2 := p.DeleteFaultSet(tc.id) | ||
if err2 != nil { | ||
if tc.expected == nil { | ||
t.Errorf("Removing fault set did not work as expected, \n\tgot: %s \n\twant: %v", err2, tc.expected) | ||
} else { | ||
if err2.Error() != tc.expected.Error() { | ||
t.Errorf("Removing fault set did not work as expected, \n\tgot: %s \n\twant: %s", err2, tc.expected) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} |