Ejemplo n.º 1
0
func TestLintEmptyChartYaml(t *testing.T) {
	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)

	chartName := "badChart"

	Create(chartName, tmpHome)

	badChartYaml, _ := yaml.Marshal(make(map[string]string))

	chartYaml := util.WorkspaceChartDirectory(tmpHome, chartName, Chartfile)

	os.Remove(chartYaml)
	ioutil.WriteFile(chartYaml, badChartYaml, 0644)

	output := test.CaptureOutput(func() {
		Lint(util.WorkspaceChartDirectory(tmpHome, chartName))
	})

	test.ExpectContains(t, output, "Chart.yaml has a name field : false")
	test.ExpectContains(t, output, "Chart.yaml has a version field : false")
	test.ExpectContains(t, output, "Chart.yaml has a description field : false")
	test.ExpectContains(t, output, "Chart.yaml has a maintainers field : false")
	test.ExpectContains(t, output, fmt.Sprintf("Chart [%s] has failed some necessary checks", chartName))
}
Ejemplo n.º 2
0
func TestPlugin(t *testing.T) {
	f := "../testdata"
	p := "plugin"
	a := []string{"myplugin", "-a", "-b", "-c"}

	os.Setenv("PATH", os.ExpandEnv("$PATH:"+test.HelmRoot+"/testdata"))

	buf, err := ioutil.TempFile("", "helm-plugin-test")
	if err != nil {
		t.Fatal(err)
	}

	oldout := os.Stdout
	os.Stdout = buf
	defer func() { os.Stdout = oldout; buf.Close(); os.Remove(buf.Name()) }()

	test.FakeUpdate(f)
	Plugin(f, p, a)

	buf.Seek(0, 0)
	b, err := ioutil.ReadAll(buf)
	if err != nil {
		t.Errorf("Failed to read tmp file: %s", err)
	}

	if strings.TrimSpace(string(b)) != "HELLO -a -b -c" {
		t.Errorf("Expected 'HELLO -a -b -c', got %v", string(b))
	}
}
Ejemplo n.º 3
0
func TestLintAllNone(t *testing.T) {
	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)

	output := test.CaptureOutput(func() {
		Cli().Run([]string{"helmc", "--home", tmpHome, "lint", "--all"})
	})

	test.ExpectContains(t, output, fmt.Sprintf("Could not find any charts in \"%s", tmpHome))
}
Ejemplo n.º 4
0
func TestListRepos(t *testing.T) {
	log.IsDebugging = true

	homedir := test.CreateTmpHome()
	test.FakeUpdate(homedir)

	actual := test.CaptureOutput(func() {
		ListRepos(homedir)
	})

	test.ExpectContains(t, actual, "charts*\thttps://github.com/helm/charts")
}
Ejemplo n.º 5
0
func TestFetch(t *testing.T) {
	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)
	chartName := "kitchensink"

	actual := test.CaptureOutput(func() {
		Fetch(chartName, "", tmpHome)
	})

	workspacePath := util.WorkspaceChartDirectory(tmpHome, chartName)
	test.ExpectContains(t, actual, "Fetched chart into workspace "+workspacePath)
}
Ejemplo n.º 6
0
func TestSearchNotFound(t *testing.T) {
	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)

	// test that a "no chart found" message was printed
	expected := "No results found"

	actual := test.CaptureOutput(func() {
		Search("nonexistent", tmpHome, false)
	})

	test.ExpectContains(t, actual, expected)
}
Ejemplo n.º 7
0
func TestLintSingle(t *testing.T) {
	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)

	chartName := "goodChart"
	action.Create(chartName, tmpHome)

	output := test.CaptureOutput(func() {
		Cli().Run([]string{"helmc", "--home", tmpHome, "lint", chartName})
	})

	test.ExpectContains(t, output, fmt.Sprintf("Chart [%s] has passed all necessary checks", chartName))
}
Ejemplo n.º 8
0
func TestUninstall(t *testing.T) {
	tests := []struct {
		name     string // Todo: print name on fail
		chart    string
		force    bool
		expected []string
		client   kubectl.Runner
	}{
		{
			name:     "with valid input",
			chart:    "redis",
			force:    true,
			expected: []string{"Running `kubectl delete` ...", "hello from redis"},
			client: TestRunner{
				out: []byte("hello from redis"),
			},
		},
		{
			name:     "with a kubectl error",
			chart:    "redis",
			force:    true,
			expected: []string{"Running `kubectl delete` ...", "Could not delete Pod redis (Skipping): oh snap"},
			client: TestRunner{
				err: errors.New("oh snap"),
			},
		},
		{
			name:  "with a helmc annotation",
			chart: "keep",
			force: true,
			expected: []string{"Running `kubectl delete` ...", "Not uninstalling",
				"because of \"helm-keep\" annotation"},
		},
	}

	tmpHome := test.CreateTmpHome()
	defer os.RemoveAll(tmpHome)
	test.FakeUpdate(tmpHome)

	for _, tt := range tests {
		Fetch(tt.chart, "", tmpHome)

		actual := test.CaptureOutput(func() {
			Uninstall(tt.chart, tmpHome, "default", tt.force, tt.client)
		})

		for _, exp := range tt.expected {
			test.ExpectContains(t, actual, exp)
		}
	}
}
Ejemplo n.º 9
0
func TestInfoFormat(t *testing.T) {

	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)

	format := `Hello {{.Name}}`
	expected := `Hello kitchensink`

	actual := test.CaptureOutput(func() {
		Info("kitchensink", tmpHome, format)
	})

	test.ExpectContains(t, actual, expected)
}
Ejemplo n.º 10
0
func TestLintMissingReadme(t *testing.T) {
	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)

	chartName := "badChart"

	Create(chartName, tmpHome)

	os.Remove(filepath.Join(util.WorkspaceChartDirectory(tmpHome, chartName), "README.md"))

	output := test.CaptureOutput(func() {
		Lint(util.WorkspaceChartDirectory(tmpHome, chartName))
	})

	test.ExpectContains(t, output, "README.md is present and not empty : false")
}
Ejemplo n.º 11
0
func TestLintSuccess(t *testing.T) {
	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)

	chartName := "goodChart"

	Create(chartName, tmpHome)

	output := test.CaptureOutput(func() {
		Lint(util.WorkspaceChartDirectory(tmpHome, chartName))
	})

	expected := "Chart [goodChart] has passed all necessary checks"

	test.ExpectContains(t, output, expected)
}
Ejemplo n.º 12
0
func TestLintMissingManifestDirectory(t *testing.T) {
	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)

	chartName := "brokeChart"

	Create(chartName, tmpHome)

	os.RemoveAll(filepath.Join(util.WorkspaceChartDirectory(tmpHome, chartName), "manifests"))

	output := test.CaptureOutput(func() {
		Lint(util.WorkspaceChartDirectory(tmpHome, chartName))
	})

	test.ExpectMatches(t, output, "Manifests directory is present : false")
	test.ExpectContains(t, output, "Chart ["+chartName+"] has failed some necessary checks")
}
Ejemplo n.º 13
0
func TestLintMissingChartYaml(t *testing.T) {
	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)

	chartName := "badChart"

	Create(chartName, tmpHome)

	os.Remove(filepath.Join(util.WorkspaceChartDirectory(tmpHome, chartName), Chartfile))

	output := test.CaptureOutput(func() {
		Lint(util.WorkspaceChartDirectory(tmpHome, chartName))
	})

	test.ExpectContains(t, output, "Chart.yaml is present : false")
	test.ExpectContains(t, output, "Chart [badChart] has failed some necessary checks.")
}
Ejemplo n.º 14
0
func TestGenerate(t *testing.T) {
	ch := "generate"
	homedir := test.CreateTmpHome()
	test.FakeUpdate(homedir)
	Fetch(ch, ch, homedir)

	Generate(ch, homedir, []string{"ignore"}, true)

	// Now we should be able to load and read the `pod.yaml` file.
	path := util.WorkspaceChartDirectory(homedir, "generate/manifests/pod.yaml")
	d, err := ioutil.ReadFile(path)
	if err != nil {
		t.Fatal(err)
	}
	pod := string(d)
	test.ExpectContains(t, pod, "image: ozo")
	test.ExpectContains(t, pod, "name: www-server")
}
Ejemplo n.º 15
0
func TestInfo(t *testing.T) {

	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)

	format := ""
	expected := `Name: kitchensink
Home: http://github.com/helm/helm
Version: 0.0.1
Description: All the things, all semantically, none working
Details: This package provides a sampling of all of the different manifest types. It can be used to test ordering and other properties of a chart.`

	actual := test.CaptureOutput(func() {
		Info("kitchensink", tmpHome, format)
	})

	test.ExpectContains(t, actual, expected)
}
Ejemplo n.º 16
0
func TestEdit(t *testing.T) {
	editor := os.Getenv("EDITOR")
	os.Setenv("EDITOR", "echo")
	defer os.Setenv("EDITOR", editor)

	tmpHome := test.CreateTmpHome()
	defer os.RemoveAll(tmpHome)
	test.FakeUpdate(tmpHome)

	Fetch("redis", "", tmpHome)

	expected := path.Join(tmpHome, "workspace/charts/redis")
	actual := test.CaptureOutput(func() {
		Edit("redis", tmpHome)
	})

	test.ExpectContains(t, actual, expected)
}
Ejemplo n.º 17
0
func TestTRemove(t *testing.T) {
	kg := kubeGet
	defer func() { kubeGet = kg }()

	tests := []struct {
		chartName string
		getter    kubeGetter
		force     bool
		expected  string
	}{
		{"kitchensink", mockNotFoundGetter, false, "All clear! You have successfully removed kitchensink from your workspace."},

		// when manifests are installed
		{"kitchensink", mockFoundGetter, false, "Found 12 installed manifests for kitchensink.  To remove a chart that has been installed the --force flag must be set."},

		// when manifests are installed and force is set
		{"kitchensink", mockNotFoundGetter, true, "All clear! You have successfully removed kitchensink from your workspace."},

		// when kubectl cannot connect
		{"kitchensink", mockFailConnection, false, "Could not determine if kitchensink is installed.  To remove the chart --force flag must be set."},

		// when kubectl cannot connect and force is set
		{"kitchensink", mockFailConnection, true, "All clear! You have successfully removed kitchensink from your workspace."},
	}

	for _, tt := range tests {
		tmpHome := test.CreateTmpHome()
		test.FakeUpdate(tmpHome)

		Fetch("kitchensink", "", tmpHome)

		// set the mock getter
		kubeGet = tt.getter

		actual := test.CaptureOutput(func() {
			Remove(tt.chartName, tmpHome, tt.force)
		})

		test.ExpectContains(t, actual, tt.expected)

		os.Remove(tmpHome)
	}
}
Ejemplo n.º 18
0
func TestLintAll(t *testing.T) {
	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)

	missingReadmeChart := "missingReadme"

	action.Create(missingReadmeChart, tmpHome)
	os.Remove(util.WorkspaceChartDirectory(tmpHome, missingReadmeChart, "README.md"))

	action.Create("goodChart", tmpHome)

	output := test.CaptureOutput(func() {
		Cli().Run([]string{"helmc", "--home", tmpHome, "lint", "--all"})
	})

	test.ExpectMatches(t, output, "A README file was not found.*"+missingReadmeChart)
	test.ExpectContains(t, output, "Chart [goodChart] has passed all necessary checks")
	test.ExpectContains(t, output, "Chart [missingReadme] failed some checks")
}
Ejemplo n.º 19
0
func TestSearch(t *testing.T) {
	tmpHome := test.CreateTmpHome()
	test.FakeUpdate(tmpHome)

	Search("homeslice", tmpHome, false)
}
Ejemplo n.º 20
0
func TestInstall(t *testing.T) {
	// Todo: add tests
	// - with an invalid chart name
	// - with failure to check dependencies
	// - with failure to check dependencies and force option
	// - with chart in current directly
	tests := []struct {
		name     string // Todo: print name on fail
		chart    string
		force    bool
		expected []string
		client   kubectl.Runner
	}{
		{
			name:     "with valid input",
			chart:    "redis",
			expected: []string{"hello from redis"},
			client: TestRunner{
				out: []byte("hello from redis"),
			},
		},
		{
			name:     "with dry-run option",
			chart:    "redis",
			expected: []string{"[CMD] kubectl create -f -"},
			client:   kubectl.PrintRunner{},
		},
		{
			name:     "with unsatisfied dependencies",
			chart:    "kitchensink",
			expected: []string{"Stopping install. Re-run with --force to install anyway."},
			client:   TestRunner{},
		},
		{
			name:     "with unsatisfied dependencies and force option",
			chart:    "kitchensink",
			force:    true,
			expected: []string{"Unsatisfied dependencies", "Running `kubectl create -f`"},
			client:   TestRunner{},
		},
		{
			name:     "with a kubectl error",
			chart:    "redis",
			expected: []string{"Failed to upload manifests: oh snap"},
			client: TestRunner{
				err: errors.New("oh snap"),
			},
		},
	}

	tmpHome := test.CreateTmpHome()
	defer os.RemoveAll(tmpHome)
	test.FakeUpdate(tmpHome)

	// Todo: get rid of this hacky mess
	pp := os.Getenv("PATH")
	defer os.Setenv("PATH", pp)
	os.Setenv("PATH", filepath.Join(test.HelmRoot, "testdata")+":"+pp)

	for _, tt := range tests {
		actual := test.CaptureOutput(func() {
			Install(tt.chart, tmpHome, "", tt.force, false, []string{}, tt.client)
		})

		for _, exp := range tt.expected {
			test.ExpectContains(t, actual, exp)
		}
	}
}