github.com/sgoings/helm@v2.0.0-alpha.2.0.20170406211108-734e92851ac3+incompatible/cmd/helm/upgrade_test.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "io" 21 "io/ioutil" 22 "os" 23 "path/filepath" 24 "testing" 25 26 "github.com/spf13/cobra" 27 28 "k8s.io/helm/pkg/chartutil" 29 "k8s.io/helm/pkg/proto/hapi/chart" 30 ) 31 32 func TestUpgradeCmd(t *testing.T) { 33 tmpChart, _ := ioutil.TempDir("testdata", "tmp") 34 defer os.RemoveAll(tmpChart) 35 cfile := &chart.Metadata{ 36 Name: "testUpgradeChart", 37 Description: "A Helm chart for Kubernetes", 38 Version: "0.1.0", 39 } 40 chartPath, err := chartutil.Create(cfile, tmpChart) 41 if err != nil { 42 t.Errorf("Error creating chart for upgrade: %v", err) 43 } 44 ch, _ := chartutil.Load(chartPath) 45 _ = releaseMock(&releaseOptions{ 46 name: "funny-bunny", 47 chart: ch, 48 }) 49 50 // update chart version 51 cfile = &chart.Metadata{ 52 Name: "testUpgradeChart", 53 Description: "A Helm chart for Kubernetes", 54 Version: "0.1.2", 55 } 56 57 chartPath, err = chartutil.Create(cfile, tmpChart) 58 if err != nil { 59 t.Errorf("Error creating chart: %v", err) 60 } 61 ch, err = chartutil.Load(chartPath) 62 if err != nil { 63 t.Errorf("Error loading updated chart: %v", err) 64 } 65 66 // update chart version again 67 cfile = &chart.Metadata{ 68 Name: "testUpgradeChart", 69 Description: "A Helm chart for Kubernetes", 70 Version: "0.1.3", 71 } 72 73 chartPath, err = chartutil.Create(cfile, tmpChart) 74 if err != nil { 75 t.Errorf("Error creating chart: %v", err) 76 } 77 var ch2 *chart.Chart 78 ch2, err = chartutil.Load(chartPath) 79 if err != nil { 80 t.Errorf("Error loading updated chart: %v", err) 81 } 82 83 originalDepsPath := filepath.Join("testdata/testcharts/reqtest") 84 missingDepsPath := filepath.Join("testdata/testcharts/chart-missing-deps") 85 var ch3 *chart.Chart 86 ch3, err = chartutil.Load(originalDepsPath) 87 if err != nil { 88 t.Errorf("Error loading chart with missing dependencies: %v", err) 89 } 90 91 tests := []releaseCase{ 92 { 93 name: "upgrade a release", 94 args: []string{"funny-bunny", chartPath}, 95 resp: releaseMock(&releaseOptions{name: "funny-bunny", version: 2, chart: ch}), 96 expected: "Release \"funny-bunny\" has been upgraded. Happy Helming!\n", 97 }, 98 { 99 name: "upgrade a release with timeout", 100 args: []string{"funny-bunny", chartPath}, 101 flags: []string{"--timeout", "120"}, 102 resp: releaseMock(&releaseOptions{name: "funny-bunny", version: 3, chart: ch2}), 103 expected: "Release \"funny-bunny\" has been upgraded. Happy Helming!\n", 104 }, 105 { 106 name: "upgrade a release with --reset-values", 107 args: []string{"funny-bunny", chartPath}, 108 flags: []string{"--reset-values", "true"}, 109 resp: releaseMock(&releaseOptions{name: "funny-bunny", version: 4, chart: ch2}), 110 expected: "Release \"funny-bunny\" has been upgraded. Happy Helming!\n", 111 }, 112 { 113 name: "upgrade a release with --reuse-values", 114 args: []string{"funny-bunny", chartPath}, 115 flags: []string{"--reuse-values", "true"}, 116 resp: releaseMock(&releaseOptions{name: "funny-bunny", version: 5, chart: ch2}), 117 expected: "Release \"funny-bunny\" has been upgraded. Happy Helming!\n", 118 }, 119 { 120 name: "install a release with 'upgrade --install'", 121 args: []string{"zany-bunny", chartPath}, 122 flags: []string{"-i"}, 123 resp: releaseMock(&releaseOptions{name: "zany-bunny", version: 1, chart: ch}), 124 expected: "Release \"zany-bunny\" has been upgraded. Happy Helming!\n", 125 }, 126 { 127 name: "install a release with 'upgrade --install' and timeout", 128 args: []string{"crazy-bunny", chartPath}, 129 flags: []string{"-i", "--timeout", "120"}, 130 resp: releaseMock(&releaseOptions{name: "crazy-bunny", version: 1, chart: ch}), 131 expected: "Release \"crazy-bunny\" has been upgraded. Happy Helming!\n", 132 }, 133 { 134 name: "upgrade a release with wait", 135 args: []string{"crazy-bunny", chartPath}, 136 flags: []string{"--wait"}, 137 resp: releaseMock(&releaseOptions{name: "crazy-bunny", version: 2, chart: ch2}), 138 expected: "Release \"crazy-bunny\" has been upgraded. Happy Helming!\n", 139 }, 140 { 141 name: "upgrade a release with missing dependencies", 142 args: []string{"bonkers-bunny", missingDepsPath}, 143 resp: releaseMock(&releaseOptions{name: "bonkers-bunny", version: 1, chart: ch3}), 144 expected: "Warning: reqsubchart2 is in requirements.yaml but not in the charts/ directory!", 145 }, 146 } 147 148 cmd := func(c *fakeReleaseClient, out io.Writer) *cobra.Command { 149 return newUpgradeCmd(c, out) 150 } 151 152 runReleaseCases(t, tests, cmd) 153 154 }