summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-04 15:38:30 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-04 15:38:33 -0700
commit9e001472ab04fb0b5b85e38266bacd9a377cc343 (patch)
treeab7bdbff68826a18c5d74947944578825c88099e /src/k8splugin/internal
parent99928f9cef81b627c2b22fcf6d7c0ca7ebe2cb0e (diff)
Use consistent naming for Name and Version
Definition Name and Definition Version are now using the consistent naming similar to the Profile and instance structure. Name becomes RBName Version becomes RBVersion Issue-ID: MULTICLOUD-350 Change-Id: Ifc329d4979a06cb017c6f9d916c227c696b664e0 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal')
-rw-r--r--src/k8splugin/internal/app/instance_test.go2
-rw-r--r--src/k8splugin/internal/rb/definition.go25
-rw-r--r--src/k8splugin/internal/rb/definition_test.go44
-rw-r--r--src/k8splugin/internal/rb/profile_test.go6
4 files changed, 39 insertions, 38 deletions
diff --git a/src/k8splugin/internal/app/instance_test.go b/src/k8splugin/internal/app/instance_test.go
index 480569c5..effd5c99 100644
--- a/src/k8splugin/internal/app/instance_test.go
+++ b/src/k8splugin/internal/app/instance_test.go
@@ -71,7 +71,7 @@ func TestInstanceCreate(t *testing.T) {
"YkDi6mRXNk/V1pUxy0uYsI1S+meU+XsPo2kJLnMOKZGy4J6Xt3XgZuHTayEKv3XZLjy+" +
"yJ66WPQwcHBwcHBwcHBwcHBwcHBwcHhm8Q/mTHqWgAoAAA="),
},
- rb.DefinitionKey{Name: "test-rbdef", Version: "v1"}.String(): {
+ rb.DefinitionKey{RBName: "test-rbdef", RBVersion: "v1"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"test-rbdef\"," +
"\"rb-version\":\"v1\"," +
diff --git a/src/k8splugin/internal/rb/definition.go b/src/k8splugin/internal/rb/definition.go
index 1c6b1bc5..bae8df0c 100644
--- a/src/k8splugin/internal/rb/definition.go
+++ b/src/k8splugin/internal/rb/definition.go
@@ -33,16 +33,17 @@ import (
// Definition contains the parameters needed for resource bundle (rb) definitions
// It implements the interface for managing the definitions
type Definition struct {
- Name string `json:"rb-name"`
- Version string `json:"rb-version"`
+ RBName string `json:"rb-name"`
+ RBVersion string `json:"rb-version"`
ChartName string `json:"chart-name"`
Description string `json:"description"`
Labels map[string]string `json:"labels"`
}
+// DefinitionKey is the key structure that is used in the database
type DefinitionKey struct {
- Name string `json:"rb-name"`
- Version string `json:"rb-version"`
+ RBName string `json:"rb-name"`
+ RBVersion string `json:"rb-version"`
}
// We will use json marshalling to convert to string to
@@ -83,14 +84,14 @@ func NewDefinitionClient() *DefinitionClient {
}
}
-// Create an entry for the resource in the database
+// Create an entry for the resource in the database`
func (v *DefinitionClient) Create(def Definition) (Definition, error) {
//Construct composite key consisting of name and version
- key := DefinitionKey{Name: def.Name, Version: def.Version}
+ key := DefinitionKey{RBName: def.RBName, RBVersion: def.RBVersion}
//Check if this definition already exists
- _, err := v.Get(def.Name, def.Version)
+ _, err := v.Get(def.RBName, def.RBVersion)
if err == nil {
return Definition{}, pkgerrors.New("Definition already exists")
}
@@ -121,7 +122,7 @@ func (v *DefinitionClient) List(name string) ([]Definition, error) {
continue
}
//Select only the definitions that match name provided
- if def.Name == name {
+ if def.RBName == name {
results = append(results, def)
}
}
@@ -134,7 +135,7 @@ func (v *DefinitionClient) List(name string) ([]Definition, error) {
func (v *DefinitionClient) Get(name string, version string) (Definition, error) {
//Construct the composite key to select the entry
- key := DefinitionKey{Name: name, Version: version}
+ key := DefinitionKey{RBName: name, RBVersion: version}
value, err := db.DBconn.Read(v.storeName, key, v.tagMeta)
if err != nil {
return Definition{}, pkgerrors.Wrap(err, "Get Resource Bundle definition")
@@ -157,7 +158,7 @@ func (v *DefinitionClient) Get(name string, version string) (Definition, error)
func (v *DefinitionClient) Delete(name string, version string) error {
//Construct the composite key to select the entry
- key := DefinitionKey{Name: name, Version: version}
+ key := DefinitionKey{RBName: name, RBVersion: version}
err := db.DBconn.Delete(v.storeName, key, v.tagMeta)
if err != nil {
return pkgerrors.Wrap(err, "Delete Resource Bundle Definition")
@@ -187,7 +188,7 @@ func (v *DefinitionClient) Upload(name string, version string, inp []byte) error
}
//Construct the composite key to select the entry
- key := DefinitionKey{Name: name, Version: version}
+ key := DefinitionKey{RBName: name, RBVersion: version}
//Detect chart name from data if it was not provided originally
if def.ChartName == "" {
@@ -246,7 +247,7 @@ func (v *DefinitionClient) Download(name string, version string) ([]byte, error)
}
//Construct the composite key to select the entry
- key := DefinitionKey{Name: name, Version: version}
+ key := DefinitionKey{RBName: name, RBVersion: version}
value, err := db.DBconn.Read(v.storeName, key, v.tagContent)
if err != nil {
return nil, pkgerrors.Wrap(err, "Get Resource Bundle definition content")
diff --git a/src/k8splugin/internal/rb/definition_test.go b/src/k8splugin/internal/rb/definition_test.go
index 0a9e7c72..a1ad0eae 100644
--- a/src/k8splugin/internal/rb/definition_test.go
+++ b/src/k8splugin/internal/rb/definition_test.go
@@ -38,14 +38,14 @@ func TestCreateDefinition(t *testing.T) {
{
label: "Create Resource Bundle Definition",
inp: Definition{
- Name: "testresourcebundle",
- Version: "v1",
+ RBName: "testresourcebundle",
+ RBVersion: "v1",
Description: "testresourcebundle",
ChartName: "",
},
expected: Definition{
- Name: "testresourcebundle",
- Version: "v1",
+ RBName: "testresourcebundle",
+ RBVersion: "v1",
Description: "testresourcebundle",
ChartName: "",
},
@@ -97,14 +97,14 @@ func TestListDefinition(t *testing.T) {
name: "testresourcebundle",
expected: []Definition{
{
- Name: "testresourcebundle",
- Version: "v1",
+ RBName: "testresourcebundle",
+ RBVersion: "v1",
Description: "testresourcebundle",
ChartName: "testchart",
},
{
- Name: "testresourcebundle",
- Version: "v2",
+ RBName: "testresourcebundle",
+ RBVersion: "v2",
Description: "testresourcebundle_version2",
ChartName: "testchart",
},
@@ -112,14 +112,14 @@ func TestListDefinition(t *testing.T) {
expectedError: "",
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- DefinitionKey{Name: "testresourcebundle", Version: "v1"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle\"," +
"\"rb-version\":\"v1\"," +
"\"chart-name\":\"testchart\"}"),
},
- DefinitionKey{Name: "testresourcebundle", Version: "v2"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v2"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle_version2\"," +
@@ -154,12 +154,12 @@ func TestListDefinition(t *testing.T) {
// 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].Version < got[j].Version
+ return got[i].RBVersion < got[j].RBVersion
})
// 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].Version < testCase.expected[j].Version
+ return testCase.expected[i].RBVersion < testCase.expected[j].RBVersion
})
if reflect.DeepEqual(testCase.expected, got) == false {
@@ -187,15 +187,15 @@ func TestGetDefinition(t *testing.T) {
name: "testresourcebundle",
version: "v1",
expected: Definition{
- Name: "testresourcebundle",
- Version: "v1",
+ RBName: "testresourcebundle",
+ RBVersion: "v1",
Description: "testresourcebundle",
ChartName: "testchart",
},
expectedError: "",
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- DefinitionKey{Name: "testresourcebundle", Version: "v1"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle\"," +
@@ -325,7 +325,7 @@ func TestUploadDefinition(t *testing.T) {
},
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- DefinitionKey{Name: "testresourcebundle", Version: "v1"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle\"," +
@@ -361,7 +361,7 @@ func TestUploadDefinition(t *testing.T) {
},
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- DefinitionKey{Name: "testresourcebundle", Version: "v1"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle\"," +
@@ -399,7 +399,7 @@ func TestUploadDefinition(t *testing.T) {
},
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- DefinitionKey{Name: "testresourcebundle", Version: "v1"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle\"," +
@@ -437,7 +437,7 @@ func TestUploadDefinition(t *testing.T) {
},
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- DefinitionKey{Name: "testresourcebundle", Version: "v1"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle\"," +
@@ -458,7 +458,7 @@ func TestUploadDefinition(t *testing.T) {
},
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- DefinitionKey{Name: "testresourcebundle", Version: "v1"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle\"," +
@@ -550,7 +550,7 @@ func TestDownloadDefinition(t *testing.T) {
},
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- DefinitionKey{Name: "testresourcebundle", Version: "v1"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle\"," +
@@ -571,7 +571,7 @@ func TestDownloadDefinition(t *testing.T) {
expectedError: "Invalid Definition ID provided",
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- DefinitionKey{Name: "testresourcebundle", Version: "v1"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle\"," +
diff --git a/src/k8splugin/internal/rb/profile_test.go b/src/k8splugin/internal/rb/profile_test.go
index 14d37d17..f99471eb 100644
--- a/src/k8splugin/internal/rb/profile_test.go
+++ b/src/k8splugin/internal/rb/profile_test.go
@@ -55,7 +55,7 @@ func TestCreateProfile(t *testing.T) {
expectedError: "",
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- DefinitionKey{Name: "testresourcebundle", Version: "v1"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle\"," +
@@ -78,7 +78,7 @@ func TestCreateProfile(t *testing.T) {
expectedError: "Error getting Resource Bundle Definition",
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- DefinitionKey{Name: "testresourcebundle", Version: "v2"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v2"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle\"," +
@@ -544,7 +544,7 @@ func TestResolveProfile(t *testing.T) {
"YkDi6mRXNk/V1pUxy0uYsI1S+meU+XsPo2kJLnMOKZGy4J6Xt3XgZuHTayEKv3XZLjy+" +
"yJ66WPQwcHBwcHBwcHBwcHBwcHBwcHhm8Q/mTHqWgAoAAA="),
},
- DefinitionKey{Name: "testresourcebundle", Version: "v1"}.String(): {
+ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
"metadata": []byte(
"{\"rb-name\":\"testresourcebundle\"," +
"\"rb-version\":\"v1\"," +