github.com/codefresh-io/kcfi@v0.0.0-20230301195427-c1578715cc46/cmd/kcfi/history_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 main
    18  
    19  import (
    20  	"fmt"
    21  	"testing"
    22  
    23  	"helm.sh/helm/v3/pkg/release"
    24  )
    25  
    26  func TestHistoryCmd(t *testing.T) {
    27  	mk := func(name string, vers int, status release.Status) *release.Release {
    28  		return release.Mock(&release.MockReleaseOptions{
    29  			Name:    name,
    30  			Version: vers,
    31  			Status:  status,
    32  		})
    33  	}
    34  
    35  	tests := []cmdTestCase{{
    36  		name: "get history for release",
    37  		cmd:  "history angry-bird",
    38  		rels: []*release.Release{
    39  			mk("angry-bird", 4, release.StatusDeployed),
    40  			mk("angry-bird", 3, release.StatusSuperseded),
    41  			mk("angry-bird", 2, release.StatusSuperseded),
    42  			mk("angry-bird", 1, release.StatusSuperseded),
    43  		},
    44  		golden: "output/history.txt",
    45  	}, {
    46  		name: "get history with max limit set",
    47  		cmd:  "history angry-bird --max 2",
    48  		rels: []*release.Release{
    49  			mk("angry-bird", 4, release.StatusDeployed),
    50  			mk("angry-bird", 3, release.StatusSuperseded),
    51  		},
    52  		golden: "output/history-limit.txt",
    53  	}, {
    54  		name: "get history with yaml output format",
    55  		cmd:  "history angry-bird --output yaml",
    56  		rels: []*release.Release{
    57  			mk("angry-bird", 4, release.StatusDeployed),
    58  			mk("angry-bird", 3, release.StatusSuperseded),
    59  		},
    60  		golden: "output/history.yaml",
    61  	}, {
    62  		name: "get history with json output format",
    63  		cmd:  "history angry-bird --output json",
    64  		rels: []*release.Release{
    65  			mk("angry-bird", 4, release.StatusDeployed),
    66  			mk("angry-bird", 3, release.StatusSuperseded),
    67  		},
    68  		golden: "output/history.json",
    69  	}}
    70  	runTestCmd(t, tests)
    71  }
    72  
    73  func TestHistoryOutputCompletion(t *testing.T) {
    74  	outputFlagCompletionTest(t, "history")
    75  }
    76  
    77  func revisionFlagCompletionTest(t *testing.T, cmdName string) {
    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  	}
    92  
    93  	tests := []cmdTestCase{{
    94  		name:   "completion for revision flag",
    95  		cmd:    fmt.Sprintf("__complete %s musketeers --revision ''", cmdName),
    96  		rels:   releases,
    97  		golden: "output/revision-comp.txt",
    98  	}, {
    99  		name:   "completion for revision flag with too few args",
   100  		cmd:    fmt.Sprintf("__complete %s --revision ''", cmdName),
   101  		rels:   releases,
   102  		golden: "output/revision-wrong-args-comp.txt",
   103  	}, {
   104  		name:   "completion for revision flag with too many args",
   105  		cmd:    fmt.Sprintf("__complete %s three musketeers --revision ''", cmdName),
   106  		rels:   releases,
   107  		golden: "output/revision-wrong-args-comp.txt",
   108  	}}
   109  	runTestCmd(t, tests)
   110  }