aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin')
-rw-r--r--src/k8splugin/api/defhandler.go4
-rw-r--r--src/k8splugin/api/defhandler_test.go36
-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
6 files changed, 59 insertions, 58 deletions
diff --git a/src/k8splugin/api/defhandler.go b/src/k8splugin/api/defhandler.go
index 93bbba15..1aa00413 100644
--- a/src/k8splugin/api/defhandler.go
+++ b/src/k8splugin/api/defhandler.go
@@ -49,13 +49,13 @@ func (h rbDefinitionHandler) createHandler(w http.ResponseWriter, r *http.Reques
}
// Name is required.
- if v.Name == "" {
+ if v.RBName == "" {
http.Error(w, "Missing name in POST request", http.StatusBadRequest)
return
}
// Version is required.
- if v.Version == "" {
+ if v.RBVersion == "" {
http.Error(w, "Missing version in POST request", http.StatusBadRequest)
return
}
diff --git a/src/k8splugin/api/defhandler_test.go b/src/k8splugin/api/defhandler_test.go
index 28bf1479..03189e1d 100644
--- a/src/k8splugin/api/defhandler_test.go
+++ b/src/k8splugin/api/defhandler_test.go
@@ -96,8 +96,8 @@ func TestRBDefCreateHandler(t *testing.T) {
"description":"test description"
}`)),
expected: rb.Definition{
- Name: "testresourcebundle",
- Version: "v1",
+ RBName: "testresourcebundle",
+ RBVersion: "v1",
ChartName: "testchart",
Description: "test description",
},
@@ -105,8 +105,8 @@ func TestRBDefCreateHandler(t *testing.T) {
//Items that will be returned by the mocked Client
Items: []rb.Definition{
{
- Name: "testresourcebundle",
- Version: "v1",
+ RBName: "testresourcebundle",
+ RBVersion: "v1",
ChartName: "testchart",
Description: "test description",
},
@@ -172,14 +172,14 @@ func TestRBDefListVersionsHandler(t *testing.T) {
expectedCode: http.StatusOK,
expected: []rb.Definition{
{
- Name: "testresourcebundle",
- Version: "v1",
+ RBName: "testresourcebundle",
+ RBVersion: "v1",
ChartName: "testchart",
Description: "test description",
},
{
- Name: "testresourcebundle",
- Version: "v2",
+ RBName: "testresourcebundle",
+ RBVersion: "v2",
ChartName: "testchart",
Description: "test description",
},
@@ -188,14 +188,14 @@ func TestRBDefListVersionsHandler(t *testing.T) {
// list of definitions that will be returned by the mockclient
Items: []rb.Definition{
{
- Name: "testresourcebundle",
- Version: "v1",
+ RBName: "testresourcebundle",
+ RBVersion: "v1",
ChartName: "testchart",
Description: "test description",
},
{
- Name: "testresourcebundle",
- Version: "v2",
+ RBName: "testresourcebundle",
+ RBVersion: "v2",
ChartName: "testchart",
Description: "test description",
},
@@ -222,12 +222,12 @@ func TestRBDefListVersionsHandler(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 {
@@ -252,8 +252,8 @@ func TestRBDefGetHandler(t *testing.T) {
label: "Get Bundle Definition",
expectedCode: http.StatusOK,
expected: rb.Definition{
- Name: "testresourcebundle",
- Version: "v1",
+ RBName: "testresourcebundle",
+ RBVersion: "v1",
ChartName: "testchart",
Description: "test description",
},
@@ -263,8 +263,8 @@ func TestRBDefGetHandler(t *testing.T) {
// list of definitions that will be returned by the mockclient
Items: []rb.Definition{
{
- Name: "testresourcebundle",
- Version: "v1",
+ RBName: "testresourcebundle",
+ RBVersion: "v1",
ChartName: "testchart",
Description: "test description",
},
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\"," +