github.com/defensepoint-snyk-test/helm-new@v0.0.0-20211130153739-c57ea64d6603/cmd/helm/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 "io" 21 "testing" 22 23 "github.com/spf13/cobra" 24 25 "k8s.io/helm/pkg/helm" 26 rpb "k8s.io/helm/pkg/proto/hapi/release" 27 ) 28 29 func TestHistoryCmd(t *testing.T) { 30 mk := func(name string, vers int32, code rpb.Status_Code) *rpb.Release { 31 return helm.ReleaseMock(&helm.MockReleaseOptions{ 32 Name: name, 33 Version: vers, 34 StatusCode: code, 35 }) 36 } 37 38 tests := []releaseCase{ 39 { 40 name: "get history for release", 41 args: []string{"angry-bird"}, 42 rels: []*rpb.Release{ 43 mk("angry-bird", 4, rpb.Status_DEPLOYED), 44 mk("angry-bird", 3, rpb.Status_SUPERSEDED), 45 mk("angry-bird", 2, rpb.Status_SUPERSEDED), 46 mk("angry-bird", 1, rpb.Status_SUPERSEDED), 47 }, 48 expected: "REVISION\tUPDATED \tSTATUS \tCHART \tDESCRIPTION \n1 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n2 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n3 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n4 \t(.*)\tDEPLOYED \tfoo-0.1.0-beta.1\tRelease mock\n", 49 }, 50 { 51 name: "get history with max limit set", 52 args: []string{"angry-bird"}, 53 flags: []string{"--max", "2"}, 54 rels: []*rpb.Release{ 55 mk("angry-bird", 4, rpb.Status_DEPLOYED), 56 mk("angry-bird", 3, rpb.Status_SUPERSEDED), 57 }, 58 expected: "REVISION\tUPDATED \tSTATUS \tCHART \tDESCRIPTION \n3 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n4 \t(.*)\tDEPLOYED \tfoo-0.1.0-beta.1\tRelease mock\n", 59 }, 60 { 61 name: "get history with yaml output format", 62 args: []string{"angry-bird"}, 63 flags: []string{"--output", "yaml"}, 64 rels: []*rpb.Release{ 65 mk("angry-bird", 4, rpb.Status_DEPLOYED), 66 mk("angry-bird", 3, rpb.Status_SUPERSEDED), 67 }, 68 expected: "- chart: foo-0.1.0-beta.1\n description: Release mock\n revision: 3\n status: SUPERSEDED\n updated: (.*)\n- chart: foo-0.1.0-beta.1\n description: Release mock\n revision: 4\n status: DEPLOYED\n updated: (.*)\n\n", 69 }, 70 { 71 name: "get history with json output format", 72 args: []string{"angry-bird"}, 73 flags: []string{"--output", "json"}, 74 rels: []*rpb.Release{ 75 mk("angry-bird", 4, rpb.Status_DEPLOYED), 76 mk("angry-bird", 3, rpb.Status_SUPERSEDED), 77 }, 78 expected: `[{"revision":3,"updated":".*","status":"SUPERSEDED","chart":"foo\-0.1.0-beta.1","description":"Release mock"},{"revision":4,"updated":".*","status":"DEPLOYED","chart":"foo\-0.1.0-beta.1","description":"Release mock"}]\n`, 79 }, 80 } 81 82 runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { 83 return newHistoryCmd(c, out) 84 }) 85 }