github.com/Racer159/helm-experiment@v0.0.0-20230822001441-1eb31183f614/src/rollback_test.go (about)

     1  /*
     2  Copyright The Helm Authors.
     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 cmd
    18  
    19  import (
    20  	"testing"
    21  
    22  	"helm.sh/helm/v3/pkg/chart"
    23  	"helm.sh/helm/v3/pkg/release"
    24  )
    25  
    26  func TestRollbackCmd(t *testing.T) {
    27  	rels := []*release.Release{
    28  		{
    29  			Name:    "funny-honey",
    30  			Info:    &release.Info{Status: release.StatusSuperseded},
    31  			Chart:   &chart.Chart{},
    32  			Version: 1,
    33  		},
    34  		{
    35  			Name:    "funny-honey",
    36  			Info:    &release.Info{Status: release.StatusDeployed},
    37  			Chart:   &chart.Chart{},
    38  			Version: 2,
    39  		},
    40  	}
    41  
    42  	tests := []cmdTestCase{{
    43  		name:   "rollback a release",
    44  		cmd:    "rollback funny-honey 1",
    45  		golden: "output/rollback.txt",
    46  		rels:   rels,
    47  	}, {
    48  		name:   "rollback a release with timeout",
    49  		cmd:    "rollback funny-honey 1 --timeout 120s",
    50  		golden: "output/rollback-timeout.txt",
    51  		rels:   rels,
    52  	}, {
    53  		name:   "rollback a release with wait",
    54  		cmd:    "rollback funny-honey 1 --wait",
    55  		golden: "output/rollback-wait.txt",
    56  		rels:   rels,
    57  	}, {
    58  		name:   "rollback a release with wait-for-jobs",
    59  		cmd:    "rollback funny-honey 1 --wait --wait-for-jobs",
    60  		golden: "output/rollback-wait-for-jobs.txt",
    61  		rels:   rels,
    62  	}, {
    63  		name:   "rollback a release without revision",
    64  		cmd:    "rollback funny-honey",
    65  		golden: "output/rollback-no-revision.txt",
    66  		rels:   rels,
    67  	}, {
    68  		name:      "rollback a release without release name",
    69  		cmd:       "rollback",
    70  		golden:    "output/rollback-no-args.txt",
    71  		rels:      rels,
    72  		wantError: true,
    73  	}}
    74  	runTestCmd(t, tests)
    75  }
    76  
    77  func TestRollbackRevisionCompletion(t *testing.T) {
    78  	mk := func(name string, vers int, status release.Status) *release.Release {
    79  		return release.Mock(&release.MockReleaseOptions{
    80  			Name:    name,
    81  			Version: vers,
    82  			Status:  status,
    83  		})
    84  	}
    85  
    86  	releases := []*release.Release{
    87  		mk("musketeers", 11, release.StatusDeployed),
    88  		mk("musketeers", 10, release.StatusSuperseded),
    89  		mk("musketeers", 9, release.StatusSuperseded),
    90  		mk("musketeers", 8, release.StatusSuperseded),
    91  		mk("carabins", 1, release.StatusSuperseded),
    92  	}
    93  
    94  	tests := []cmdTestCase{{
    95  		name:   "completion for release parameter",
    96  		cmd:    "__complete rollback ''",
    97  		rels:   releases,
    98  		golden: "output/rollback-comp.txt",
    99  	}, {
   100  		name:   "completion for revision parameter",
   101  		cmd:    "__complete rollback musketeers ''",
   102  		rels:   releases,
   103  		golden: "output/revision-comp.txt",
   104  	}, {
   105  		name:   "completion for with too many args",
   106  		cmd:    "__complete rollback musketeers 11 ''",
   107  		rels:   releases,
   108  		golden: "output/rollback-wrong-args-comp.txt",
   109  	}}
   110  	runTestCmd(t, tests)
   111  }
   112  
   113  func TestRollbackFileCompletion(t *testing.T) {
   114  	checkFileCompletion(t, "rollback", false)
   115  	checkFileCompletion(t, "rollback myrelease", false)
   116  	checkFileCompletion(t, "rollback myrelease 1", false)
   117  }