diff options
author | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-07-18 14:49:25 -0700 |
---|---|---|
committer | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-07-18 17:14:18 -0700 |
commit | 412d02f7bd53a9e810be2c17d1c391c9bc6dda13 (patch) | |
tree | 78e56002bd30c7273ae1bb14d9589601a5e74e3b /src/k8splugin/internal/rb/profile_test.go | |
parent | d605586c571f5bc059486d3b41a9709b5d9c10e3 (diff) |
Add list api for profiles
Add a list api for profiles for a specific
definition and version.
GET /v1/rb/definition/name/version/profile
will list all the profiles.
Issue-ID: MULTICLOUD-730
Change-Id: If1b8e6910c276a0f7139ab13340721c6ec8a49e8
Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/rb/profile_test.go')
-rw-r--r-- | src/k8splugin/internal/rb/profile_test.go | 104 |
1 files changed, 103 insertions, 1 deletions
diff --git a/src/k8splugin/internal/rb/profile_test.go b/src/k8splugin/internal/rb/profile_test.go index 263c48ab..26b0161d 100644 --- a/src/k8splugin/internal/rb/profile_test.go +++ b/src/k8splugin/internal/rb/profile_test.go @@ -18,11 +18,13 @@ package rb import ( "bytes" - "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" "reflect" + "sort" "strings" "testing" + "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" + pkgerrors "github.com/pkg/errors" ) @@ -187,6 +189,106 @@ func TestGetProfile(t *testing.T) { } } +func TestListProfile(t *testing.T) { + + testCases := []struct { + label string + name string + rbdef string + version string + expectedError string + mockdb *db.MockDB + expected []Profile + }{ + { + label: "List Resource Bundle Profile", + name: "testresourcebundle", + rbdef: "testresourcebundle", + version: "v1", + expected: []Profile{ + { + ProfileName: "testprofile1", + ReleaseName: "testprofilereleasename", + Namespace: "testnamespace", + KubernetesVersion: "1.12.3", + RBName: "testresourcebundle", + RBVersion: "v1", + }, + { + ProfileName: "testprofile2", + ReleaseName: "testprofilereleasename2", + Namespace: "testnamespace2", + KubernetesVersion: "1.12.3", + RBName: "testresourcebundle", + RBVersion: "v1", + }, + }, + expectedError: "", + mockdb: &db.MockDB{ + Items: map[string]map[string][]byte{ + ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile1"}.String(): { + "profilemetadata": []byte( + "{\"profile-name\":\"testprofile1\"," + + "\"release-name\":\"testprofilereleasename\"," + + "\"namespace\":\"testnamespace\"," + + "\"rb-name\":\"testresourcebundle\"," + + "\"rb-version\":\"v1\"," + + "\"kubernetes-version\":\"1.12.3\"}"), + }, + ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile2"}.String(): { + "profilemetadata": []byte( + "{\"profile-name\":\"testprofile2\"," + + "\"release-name\":\"testprofilereleasename2\"," + + "\"namespace\":\"testnamespace2\"," + + "\"rb-name\":\"testresourcebundle\"," + + "\"rb-version\":\"v1\"," + + "\"kubernetes-version\":\"1.12.3\"}"), + }, + }, + }, + }, + { + label: "List Error", + expectedError: "DB Error", + mockdb: &db.MockDB{ + Err: pkgerrors.New("DB Error"), + }, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.label, func(t *testing.T) { + db.DBconn = testCase.mockdb + impl := NewProfileClient() + got, err := impl.List(testCase.rbdef, testCase.version) + if err != nil { + if testCase.expectedError == "" { + t.Fatalf("List returned an unexpected error %s", err) + } + if strings.Contains(err.Error(), testCase.expectedError) == false { + t.Fatalf("List returned an unexpected error %s", err) + } + } else { + // Since the order of returned slice is not guaranteed + // Check both and return error if both don't match + sort.Slice(got, func(i, j int) bool { + return got[i].ProfileName < got[j].ProfileName + }) + // Sort both as it is not expected that testCase.expected + // is sorted + sort.Slice(testCase.expected, func(i, j int) bool { + return testCase.expected[i].ProfileName < testCase.expected[j].ProfileName + }) + + if reflect.DeepEqual(testCase.expected, got) == false { + t.Errorf("List Resource Bundle returned unexpected body: got %v;"+ + " expected %v", got, testCase.expected) + } + } + }) + } +} + func TestDeleteProfile(t *testing.T) { testCases := []struct { |