github.com/danielqsj/helm@v2.0.0-alpha.4.0.20160908204436-976e0ba5199b+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  	"testing"
    24  
    25  	"github.com/spf13/cobra"
    26  
    27  	"k8s.io/helm/pkg/chartutil"
    28  	"k8s.io/helm/pkg/proto/hapi/chart"
    29  )
    30  
    31  func TestUpgradeCmd(t *testing.T) {
    32  	tmpChart, _ := ioutil.TempDir("testdata", "tmp")
    33  	defer os.RemoveAll(tmpChart)
    34  	cfile := &chart.Metadata{
    35  		Name:        "testUpgradeChart",
    36  		Description: "A Helm chart for Kubernetes",
    37  		Version:     "0.1.0",
    38  	}
    39  	chartPath, err := chartutil.Create(cfile, tmpChart)
    40  	if err != nil {
    41  		t.Errorf("Error creating chart for upgrade: %v", err)
    42  	}
    43  	ch, _ := chartutil.Load(chartPath)
    44  	_ = releaseMock(&releaseOptions{
    45  		name:  "funny-bunny",
    46  		chart: ch,
    47  	})
    48  
    49  	// update chart version
    50  	cfile = &chart.Metadata{
    51  		Name:        "testUpgradeChart",
    52  		Description: "A Helm chart for Kubernetes",
    53  		Version:     "0.1.2",
    54  	}
    55  
    56  	chartPath, err = chartutil.Create(cfile, tmpChart)
    57  	if err != nil {
    58  		t.Errorf("Error creating chart: %v", err)
    59  	}
    60  	ch, err = chartutil.Load(chartPath)
    61  	if err != nil {
    62  		t.Errorf("Error loading updated chart: %v", err)
    63  	}
    64  
    65  	tests := []releaseCase{
    66  		{
    67  			name:     "upgrade a release",
    68  			args:     []string{"funny-bunny", chartPath},
    69  			resp:     releaseMock(&releaseOptions{name: "funny-bunny", version: 2, chart: ch}),
    70  			expected: "funny-bunny has been upgraded. Happy Helming!\n",
    71  		},
    72  	}
    73  
    74  	cmd := func(c *fakeReleaseClient, out io.Writer) *cobra.Command {
    75  		return newUpgradeCmd(c, out)
    76  	}
    77  
    78  	runReleaseCases(t, tests, cmd)
    79  
    80  }