Skip to content

Commit

Permalink
Merge pull request #262 from Praqma/fix/247
Browse files Browse the repository at this point in the history
quote chart path when validating. fixes #247
  • Loading branch information
Sami Alajrami authored Jun 26, 2019
2 parents 1f61640 + 9ed64e7 commit abeb53f
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ check: $(SRCDIR)

test: dep ## Run unit tests
@cd $(SRCDIR)helmsman && \
helm init --client-only && \
go test -v -cover -p=1 -args -f example.toml
.PHONY: test

Expand Down
2 changes: 1 addition & 1 deletion helm_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func validateReleaseCharts(apps map[string]*release) (bool, string) {
if isLocal {
cmd := command{
Cmd: "bash",
Args: []string{"-c", "helm inspect chart " + r.Chart},
Args: []string{"-c", "helm inspect chart '" + r.Chart + "'"},
Description: "validating if chart at " + r.Chart + " is available.",
}

Expand Down
163 changes: 163 additions & 0 deletions helm_helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,173 @@
package main

import (
"os"
"testing"
"time"
)

func setupTestCase(t *testing.T) func(t *testing.T) {
t.Log("setup test case")
os.MkdirAll("/tmp/helmsman-tests/myapp", os.ModePerm)
os.MkdirAll("/tmp/helmsman-tests/dir-with space/myapp", os.ModePerm)
cmd := command{
Cmd: "bash",
Args: []string{"-c", "helm create '/tmp/helmsman-tests/dir-with space/myapp'"},
Description: "creating an empty local chart directory",
}
if exitCode, msg := cmd.exec(debug, verbose); exitCode != 0 {
logError("Command returned with exit code: " + string(exitCode) + ". And error message: " + msg)
}

return func(t *testing.T) {
t.Log("teardown test case")
//os.RemoveAll("/tmp/helmsman-tests/")
}
}
func Test_validateReleaseCharts(t *testing.T) {
type args struct {
apps map[string]*release
}
tests := []struct {
name string
args args
want bool
}{
{
name: "test case 1: valid local path with no chart",
args: args{
apps: map[string]*release{
"app": &release{
Name: "",
Description: "",
Namespace: "",
Enabled: true,
Chart: "/tmp/helmsman-tests/myapp",
Version: "",
ValuesFile: "",
ValuesFiles: []string{},
SecretsFile: "",
SecretsFiles: []string{},
Purge: false,
Test: false,
Protected: false,
Wait: false,
Priority: 0,
TillerNamespace: "",
Set: make(map[string]string),
SetString: make(map[string]string),
HelmFlags: []string{},
NoHooks: false,
Timeout: 0,
},
},
},
want: false,
}, {
name: "test case 2: invalid local path",
args: args{
apps: map[string]*release{
"app": &release{
Name: "",
Description: "",
Namespace: "",
Enabled: true,
Chart: "/tmp/does-not-exist/myapp",
Version: "",
ValuesFile: "",
ValuesFiles: []string{},
SecretsFile: "",
SecretsFiles: []string{},
Purge: false,
Test: false,
Protected: false,
Wait: false,
Priority: 0,
TillerNamespace: "",
Set: make(map[string]string),
SetString: make(map[string]string),
HelmFlags: []string{},
NoHooks: false,
Timeout: 0,
},
},
},
want: false,
}, {
name: "test case 3: valid chart local path with whitespace",
args: args{
apps: map[string]*release{
"app": &release{
Name: "",
Description: "",
Namespace: "",
Enabled: true,
Chart: "/tmp/helmsman-tests/dir-with space/myapp",
Version: "0.1.0",
ValuesFile: "",
ValuesFiles: []string{},
SecretsFile: "",
SecretsFiles: []string{},
Purge: false,
Test: false,
Protected: false,
Wait: false,
Priority: 0,
TillerNamespace: "",
Set: make(map[string]string),
SetString: make(map[string]string),
HelmFlags: []string{},
NoHooks: false,
Timeout: 0,
},
},
},
want: true,
}, {
name: "test case 4: valid chart from repo",
args: args{
apps: map[string]*release{
"app": &release{
Name: "",
Description: "",
Namespace: "",
Enabled: true,
Chart: "stable/prometheus",
Version: "",
ValuesFile: "",
ValuesFiles: []string{},
SecretsFile: "",
SecretsFiles: []string{},
Purge: false,
Test: false,
Protected: false,
Wait: false,
Priority: 0,
TillerNamespace: "",
Set: make(map[string]string),
SetString: make(map[string]string),
HelmFlags: []string{},
NoHooks: false,
Timeout: 0,
},
},
},
want: true,
},
}

teardownTestCase := setupTestCase(t)
defer teardownTestCase(t)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

if got, msg := validateReleaseCharts(tt.args.apps); got != tt.want {
t.Errorf("getReleaseChartName() = %v, want %v , msg: %v", got, tt.want, msg)
}
})
}
}

func Test_getReleaseChartVersion(t *testing.T) {
// version string = the first semver-valid string after the last hypen in the chart string.

Expand Down

0 comments on commit abeb53f

Please sign in to comment.