mirror of https://github.com/helm/helm
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
4.3 KiB
147 lines
4.3 KiB
/*
|
|
Copyright The Helm Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"k8s.io/helm/pkg/chart"
|
|
"k8s.io/helm/pkg/chart/loader"
|
|
"k8s.io/helm/pkg/chartutil"
|
|
"k8s.io/helm/pkg/hapi/release"
|
|
"k8s.io/helm/pkg/helm"
|
|
)
|
|
|
|
func TestUpgradeCmd(t *testing.T) {
|
|
tmpChart := testTempDir(t)
|
|
cfile := &chart.Metadata{
|
|
Name: "testUpgradeChart",
|
|
Description: "A Helm chart for Kubernetes",
|
|
Version: "0.1.0",
|
|
}
|
|
chartPath, err := chartutil.Create(cfile, tmpChart)
|
|
if err != nil {
|
|
t.Fatalf("Error creating chart for upgrade: %v", err)
|
|
}
|
|
ch, err := loader.Load(chartPath)
|
|
if err != nil {
|
|
t.Fatalf("Error loading chart: %v", err)
|
|
}
|
|
_ = helm.ReleaseMock(&helm.MockReleaseOptions{
|
|
Name: "funny-bunny",
|
|
Chart: ch,
|
|
})
|
|
|
|
// update chart version
|
|
cfile = &chart.Metadata{
|
|
Name: "testUpgradeChart",
|
|
Description: "A Helm chart for Kubernetes",
|
|
Version: "0.1.2",
|
|
}
|
|
|
|
chartPath, err = chartutil.Create(cfile, tmpChart)
|
|
if err != nil {
|
|
t.Fatalf("Error creating chart: %v", err)
|
|
}
|
|
ch, err = loader.Load(chartPath)
|
|
if err != nil {
|
|
t.Fatalf("Error loading updated chart: %v", err)
|
|
}
|
|
|
|
// update chart version again
|
|
cfile = &chart.Metadata{
|
|
Name: "testUpgradeChart",
|
|
Description: "A Helm chart for Kubernetes",
|
|
Version: "0.1.3",
|
|
}
|
|
|
|
chartPath, err = chartutil.Create(cfile, tmpChart)
|
|
if err != nil {
|
|
t.Fatalf("Error creating chart: %v", err)
|
|
}
|
|
var ch2 *chart.Chart
|
|
ch2, err = loader.Load(chartPath)
|
|
if err != nil {
|
|
t.Fatalf("Error loading updated chart: %v", err)
|
|
}
|
|
|
|
missingDepsPath := "testdata/testcharts/chart-missing-deps"
|
|
badDepsPath := "testdata/testcharts/chart-bad-requirements"
|
|
|
|
relMock := func(n string, v int, ch *chart.Chart) *release.Release {
|
|
return helm.ReleaseMock(&helm.MockReleaseOptions{Name: n, Version: v, Chart: ch})
|
|
}
|
|
|
|
tests := []cmdTestCase{
|
|
{
|
|
name: "upgrade a release",
|
|
cmd: "upgrade funny-bunny " + chartPath,
|
|
golden: "output/upgrade.txt",
|
|
rels: []*release.Release{relMock("funny-bunny", 2, ch)},
|
|
},
|
|
{
|
|
name: "upgrade a release with timeout",
|
|
cmd: "upgrade funny-bunny --timeout 120 " + chartPath,
|
|
golden: "output/upgrade-with-timeout.txt",
|
|
rels: []*release.Release{relMock("funny-bunny", 3, ch2)},
|
|
},
|
|
{
|
|
name: "upgrade a release with --reset-values",
|
|
cmd: "upgrade funny-bunny --reset-values " + chartPath,
|
|
golden: "output/upgrade-with-reset-values.txt",
|
|
rels: []*release.Release{relMock("funny-bunny", 4, ch2)},
|
|
},
|
|
{
|
|
name: "upgrade a release with --reuse-values",
|
|
cmd: "upgrade funny-bunny --reuse-values " + chartPath,
|
|
golden: "output/upgrade-with-reset-values2.txt",
|
|
rels: []*release.Release{relMock("funny-bunny", 5, ch2)},
|
|
},
|
|
{
|
|
name: "install a release with 'upgrade --install'",
|
|
cmd: "upgrade zany-bunny -i " + chartPath,
|
|
golden: "output/upgrade-with-install.txt",
|
|
rels: []*release.Release{relMock("zany-bunny", 1, ch)},
|
|
},
|
|
{
|
|
name: "install a release with 'upgrade --install' and timeout",
|
|
cmd: "upgrade crazy-bunny -i --timeout 120 " + chartPath,
|
|
golden: "output/upgrade-with-install-timeout.txt",
|
|
rels: []*release.Release{relMock("crazy-bunny", 1, ch)},
|
|
},
|
|
{
|
|
name: "upgrade a release with wait",
|
|
cmd: "upgrade crazy-bunny --wait " + chartPath,
|
|
golden: "output/upgrade-with-wait.txt",
|
|
rels: []*release.Release{relMock("crazy-bunny", 2, ch2)},
|
|
},
|
|
{
|
|
name: "upgrade a release with missing dependencies",
|
|
cmd: "upgrade bonkers-bunny" + missingDepsPath,
|
|
golden: "output/upgrade-with-missing-dependencies.txt",
|
|
wantError: true,
|
|
},
|
|
{
|
|
name: "upgrade a release with bad dependencies",
|
|
cmd: "upgrade bonkers-bunny " + badDepsPath,
|
|
golden: "output/upgrade-with-bad-dependencies.txt",
|
|
wantError: true,
|
|
},
|
|
}
|
|
runTestCmd(t, tests)
|
|
}
|