From f3875e13c7a6675aa980c29580daae42a32eb97f Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Fri, 29 Mar 2019 16:07:47 -0700 Subject: Make profile key explicit Using profilename instead of name in the db key protects it from getting overwritten by anything else that might use name as a key. Using explicit key names makes sure that we don't have to add bson structure tags in the code. Issue-ID: MULTICLOUD-558 Change-Id: I9bd6f757496af22d8662b0d114f0ef7d33a5784a Signed-off-by: Kiran Kamineni --- src/k8splugin/api/handler_test.go | 4 ++-- src/k8splugin/api/profilehandler.go | 2 +- src/k8splugin/api/profilehandler_test.go | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/k8splugin/api') diff --git a/src/k8splugin/api/handler_test.go b/src/k8splugin/api/handler_test.go index ee4a3005..eacefe65 100644 --- a/src/k8splugin/api/handler_test.go +++ b/src/k8splugin/api/handler_test.go @@ -127,7 +127,7 @@ func TestCreateHandler(t *testing.T) { mockStore: &db.MockDB{ Items: map[string]map[string][]byte{ rb.ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", - Name: "profile1"}.String(): { + ProfileName: "profile1"}.String(): { "metadata": []byte( "{\"profile-name\":\"profile1\"," + "\"release-name\":\"testprofilereleasename\"," + @@ -272,7 +272,7 @@ func TestCreateHandler(t *testing.T) { mockStore: &db.MockDB{ Items: map[string]map[string][]byte{ rb.ProfileKey{RBName: "test-rbdef", RBVersion: "v1", - Name: "profile1"}.String(): { + ProfileName: "profile1"}.String(): { "metadata": []byte( "{\"profile-name\":\"profile1\"," + "\"release-name\":\"testprofilereleasename\"," + diff --git a/src/k8splugin/api/profilehandler.go b/src/k8splugin/api/profilehandler.go index 2c15a440..362289ff 100644 --- a/src/k8splugin/api/profilehandler.go +++ b/src/k8splugin/api/profilehandler.go @@ -49,7 +49,7 @@ func (h rbProfileHandler) createHandler(w http.ResponseWriter, r *http.Request) } // Name is required. - if p.Name == "" { + if p.ProfileName == "" { http.Error(w, "Missing name in POST request", http.StatusBadRequest) return } diff --git a/src/k8splugin/api/profilehandler_test.go b/src/k8splugin/api/profilehandler_test.go index 4e346862..e6a87129 100644 --- a/src/k8splugin/api/profilehandler_test.go +++ b/src/k8splugin/api/profilehandler_test.go @@ -92,7 +92,7 @@ func TestRBProfileCreateHandler(t *testing.T) { expected: rb.Profile{ RBName: "testresource_bundle_definition", RBVersion: "v1", - Name: "profile1", + ProfileName: "profile1", ReleaseName: "testprofilereleasename", Namespace: "default", KubernetesVersion: "1.12.3", @@ -103,7 +103,7 @@ func TestRBProfileCreateHandler(t *testing.T) { { RBName: "testresource_bundle_definition", RBVersion: "v1", - Name: "profile1", + ProfileName: "profile1", ReleaseName: "testprofilereleasename", Namespace: "default", KubernetesVersion: "1.12.3", @@ -156,7 +156,7 @@ func TestRBProfileGetHandler(t *testing.T) { expected: rb.Profile{ RBName: "testresource_bundle_definition", RBVersion: "v1", - Name: "profile1", + ProfileName: "profile1", ReleaseName: "testprofilereleasename", Namespace: "default", KubernetesVersion: "1.12.3", @@ -168,7 +168,7 @@ func TestRBProfileGetHandler(t *testing.T) { { RBName: "testresource_bundle_definition", RBVersion: "v1", - Name: "profile1", + ProfileName: "profile1", ReleaseName: "testprofilereleasename", Namespace: "default", KubernetesVersion: "1.12.3", -- cgit 1.2.3-korg