|
@@ -7,13 +7,10 @@ import (
|
|
|
"strings"
|
|
"strings"
|
|
|
"testing"
|
|
"testing"
|
|
|
|
|
|
|
|
- "github.com/porter-dev/porter/internal/config"
|
|
|
|
|
"github.com/porter-dev/porter/internal/helm"
|
|
"github.com/porter-dev/porter/internal/helm"
|
|
|
- "github.com/porter-dev/porter/internal/logger"
|
|
|
|
|
|
|
|
|
|
"helm.sh/helm/v3/pkg/chart"
|
|
"helm.sh/helm/v3/pkg/chart"
|
|
|
"helm.sh/helm/v3/pkg/release"
|
|
"helm.sh/helm/v3/pkg/release"
|
|
|
- "helm.sh/helm/v3/pkg/storage"
|
|
|
|
|
"helm.sh/helm/v3/pkg/storage/driver"
|
|
"helm.sh/helm/v3/pkg/storage/driver"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -25,28 +22,6 @@ type releaseStub struct {
|
|
|
status release.Status
|
|
status release.Status
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// type ListFilter struct {
|
|
|
|
|
-// Namespace string `json:"namespace"`
|
|
|
|
|
-// Limit int `json:"limit"`
|
|
|
|
|
-// Skip int `json:"skip"`
|
|
|
|
|
-// ByDate bool `json:"byDate"`
|
|
|
|
|
-// StatusFilter []string `json:"statusFilter"`
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// type Form struct {
|
|
|
|
|
-// KubeConfig []byte `form:"required"`
|
|
|
|
|
-// AllowedContexts []string `form:"required"`
|
|
|
|
|
-// Context string `json:"context" form:"required"`
|
|
|
|
|
-// Storage string `json:"storage" form:"oneof=secret configmap memory"`
|
|
|
|
|
-// Namespace string `json:"namespace"`
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// type ListChartForm struct {
|
|
|
|
|
-// HelmOptions *helm.Form `json:"helm" form:"required"`
|
|
|
|
|
-// ListFilter *helm.ListFilter `json:"filter" form:"required"`
|
|
|
|
|
-// UserID uint `json:"user_id"`
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
// ------------------------- TEST TYPES AND MAIN LOOP ------------------------- //
|
|
// ------------------------- TEST TYPES AND MAIN LOOP ------------------------- //
|
|
|
|
|
|
|
|
type chartTest struct {
|
|
type chartTest struct {
|
|
@@ -64,8 +39,7 @@ type chartTest struct {
|
|
|
func testChartRequests(t *testing.T, tests []*chartTest, canQuery bool) {
|
|
func testChartRequests(t *testing.T, tests []*chartTest, canQuery bool) {
|
|
|
for _, c := range tests {
|
|
for _, c := range tests {
|
|
|
// create a new tester
|
|
// create a new tester
|
|
|
- storage := helm.StorageMap["memory"](nil, "", nil)
|
|
|
|
|
- tester := newTester(canQuery, storage)
|
|
|
|
|
|
|
+ tester := newTester(canQuery)
|
|
|
|
|
|
|
|
// if there's an initializer, call it
|
|
// if there's an initializer, call it
|
|
|
for _, init := range c.initializers {
|
|
for _, init := range c.initializers {
|
|
@@ -142,12 +116,41 @@ func TestHandleListCharts(t *testing.T) {
|
|
|
testChartRequests(t, listChartsTests, true)
|
|
testChartRequests(t, listChartsTests, true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+var getChartTests = []*chartTest{
|
|
|
|
|
+ &chartTest{
|
|
|
|
|
+ initializers: []func(tester *tester){
|
|
|
|
|
+ initDefaultCharts,
|
|
|
|
|
+ },
|
|
|
|
|
+ msg: "Get charts",
|
|
|
|
|
+ method: "GET",
|
|
|
|
|
+ endpoint: "/api/charts/airwatch/0",
|
|
|
|
|
+ body: `{
|
|
|
|
|
+ "user_id": 1,
|
|
|
|
|
+ "helm": {
|
|
|
|
|
+ "namespace": "",
|
|
|
|
|
+ "context": "context-test",
|
|
|
|
|
+ "storage": "memory"
|
|
|
|
|
+ }
|
|
|
|
|
+ }`,
|
|
|
|
|
+ expStatus: http.StatusOK,
|
|
|
|
|
+ expBody: releaseStubToChartJSON(sampleReleaseStubs[0]),
|
|
|
|
|
+ useCookie: true,
|
|
|
|
|
+ validators: []func(c *chartTest, tester *tester, t *testing.T){
|
|
|
|
|
+ chartReleaseBodyValidator,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func TestHandleGetChart(t *testing.T) {
|
|
|
|
|
+ testChartRequests(t, getChartTests, true)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// ------------------------- INITIALIZERS AND VALIDATORS ------------------------- //
|
|
// ------------------------- INITIALIZERS AND VALIDATORS ------------------------- //
|
|
|
|
|
|
|
|
func initDefaultCharts(tester *tester) {
|
|
func initDefaultCharts(tester *tester) {
|
|
|
initUserDefault(tester)
|
|
initUserDefault(tester)
|
|
|
|
|
|
|
|
- agent := newAgentFixture("default", tester.app.HelmTestStorageDriver)
|
|
|
|
|
|
|
+ agent := tester.app.TestAgents.HelmAgent
|
|
|
|
|
|
|
|
makeReleases(agent, sampleReleaseStubs)
|
|
makeReleases(agent, sampleReleaseStubs)
|
|
|
|
|
|
|
@@ -156,19 +159,6 @@ func initDefaultCharts(tester *tester) {
|
|
|
agent.ActionConfig.Releases.Driver.(*driver.Memory).SetNamespace("")
|
|
agent.ActionConfig.Releases.Driver.(*driver.Memory).SetNamespace("")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func newAgentFixture(namespace string, storage *storage.Storage) *helm.Agent {
|
|
|
|
|
- l := logger.NewConsole(true)
|
|
|
|
|
- opts := &helm.Form{
|
|
|
|
|
- Namespace: namespace,
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- agent, _ := opts.ToAgent(l, &config.HelmGlobalConf{
|
|
|
|
|
- IsTesting: true,
|
|
|
|
|
- }, storage)
|
|
|
|
|
-
|
|
|
|
|
- return agent
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
var sampleReleaseStubs = []releaseStub{
|
|
var sampleReleaseStubs = []releaseStub{
|
|
|
releaseStub{"airwatch", "default", 1, "1.0.0", release.StatusDeployed},
|
|
releaseStub{"airwatch", "default", 1, "1.0.0", release.StatusDeployed},
|
|
|
releaseStub{"not-in-default-namespace", "other", 1, "1.0.1", release.StatusDeployed},
|
|
releaseStub{"not-in-default-namespace", "other", 1, "1.0.1", release.StatusDeployed},
|
|
@@ -189,6 +179,14 @@ func releaseStubsToChartJSON(rels []releaseStub) string {
|
|
|
return string(str)
|
|
return string(str)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func releaseStubToChartJSON(r releaseStub) string {
|
|
|
|
|
+ rel := releaseStubToRelease(r)
|
|
|
|
|
+
|
|
|
|
|
+ str, _ := json.Marshal(rel)
|
|
|
|
|
+
|
|
|
|
|
+ return string(str)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func releaseStubToRelease(r releaseStub) *release.Release {
|
|
func releaseStubToRelease(r releaseStub) *release.Release {
|
|
|
return &release.Release{
|
|
return &release.Release{
|
|
|
Name: r.name,
|
|
Name: r.name,
|