github.com/latiif/helm@v2.15.0+incompatible/cmd/helm/search_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 "strings" 22 "testing" 23 24 "github.com/spf13/cobra" 25 26 "k8s.io/helm/pkg/helm" 27 ) 28 29 func TestSearchCmd(t *testing.T) { 30 tests := []releaseCase{ 31 { 32 name: "search for 'maria', expect one match", 33 args: []string{"maria"}, 34 expected: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/mariadb\t0.3.0 \t \tChart for MariaDB", 35 }, 36 { 37 name: "search for 'alpine', expect two matches", 38 args: []string{"alpine"}, 39 expected: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.2.0 \t2.3.4 \tDeploy a basic Alpine Linux pod", 40 }, 41 { 42 name: "search for 'alpine' with versions, expect three matches", 43 args: []string{"alpine"}, 44 flags: []string{"--versions"}, 45 expected: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.2.0 \t2.3.4 \tDeploy a basic Alpine Linux pod\ntesting/alpine\t0.1.0 \t1.2.3 \tDeploy a basic Alpine Linux pod", 46 }, 47 { 48 name: "search for 'alpine' with version constraint, expect one match with version 0.1.0", 49 args: []string{"alpine"}, 50 flags: []string{"--version", ">= 0.1, < 0.2"}, 51 expected: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.1.0 \t1.2.3 \tDeploy a basic Alpine Linux pod", 52 }, 53 { 54 name: "search for 'alpine' with version constraint, expect one match with version 0.1.0", 55 args: []string{"alpine"}, 56 flags: []string{"--versions", "--version", ">= 0.1, < 0.2"}, 57 expected: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.1.0 \t1.2.3 \tDeploy a basic Alpine Linux pod", 58 }, 59 { 60 name: "search for 'alpine' with version constraint, expect one match with version 0.2.0", 61 args: []string{"alpine"}, 62 flags: []string{"--version", ">= 0.1"}, 63 expected: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.2.0 \t2.3.4 \tDeploy a basic Alpine Linux pod", 64 }, 65 { 66 name: "search for 'alpine' with version constraint and --versions, expect two matches", 67 args: []string{"alpine"}, 68 flags: []string{"--versions", "--version", ">= 0.1"}, 69 expected: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.2.0 \t2.3.4 \tDeploy a basic Alpine Linux pod\ntesting/alpine\t0.1.0 \t1.2.3 \tDeploy a basic Alpine Linux pod", 70 }, 71 { 72 name: "search for 'syzygy', expect no matches", 73 args: []string{"syzygy"}, 74 expected: "No results found", 75 }, 76 { 77 name: "search for 'alp[a-z]+', expect two matches", 78 args: []string{"alp[a-z]+"}, 79 flags: []string{"--regexp"}, 80 expected: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.2.0 \t2.3.4 \tDeploy a basic Alpine Linux pod", 81 }, 82 { 83 name: "search for 'alp[', expect failure to compile regexp", 84 args: []string{"alp["}, 85 flags: []string{"--regexp"}, 86 err: true, 87 }, 88 { 89 name: "search for 'maria', expect one match output json", 90 args: []string{"maria"}, 91 flags: strings.Split("--output json", " "), 92 expected: `[{"Name":"testing/mariadb","Version":"0.3.0","Appversion":"","Description":"Chart for MariaDB"}]`, 93 }, 94 { 95 name: "search for 'alpine', expect two matches output json", 96 args: []string{"alpine"}, 97 flags: strings.Split("--output json", " "), 98 expected: `[{"Name":"testing/alpine","Version":"0.2.0","Appversion":"2.3.4","Description":"Deploy a basic Alpine Linux pod"}]`, 99 }, 100 { 101 name: "search for 'maria', expect one match output yaml", 102 args: []string{"maria"}, 103 flags: strings.Split("--output yaml", " "), 104 expected: "- AppVersion: \"\"\n Description: Chart for MariaDB\n Name: testing/mariadb\n Version: 0.3.0\n\n", 105 }, 106 { 107 name: "search for 'alpine', expect two matches output yaml", 108 args: []string{"alpine"}, 109 flags: strings.Split("--output yaml", " "), 110 expected: "- AppVersion: 2.3.4\n Description: Deploy a basic Alpine Linux pod\n Name: testing/alpine\n Version: 0.2.0\n\n", 111 }, 112 } 113 114 cleanup := resetEnv() 115 defer cleanup() 116 117 settings.Home = "testdata/helmhome" 118 119 runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { 120 return newSearchCmd(out) 121 }) 122 }