github.com/wuhuizuo/helm@v3.0.0-beta.3+incompatible/cmd/helm/search_repo_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 "testing" 21 ) 22 23 func TestSearchRepositoriesCmd(t *testing.T) { 24 repoFile := "testdata/helmhome/helm/repositories.yaml" 25 repoCache := "testdata/helmhome/helm/repository" 26 27 tests := []cmdTestCase{{ 28 name: "search for 'alpine', expect two matches", 29 cmd: "search repo alpine", 30 golden: "output/search-multiple.txt", 31 }, { 32 name: "search for 'alpine', expect two matches", 33 cmd: "search repo alpine", 34 golden: "output/search-multiple.txt", 35 }, { 36 name: "search for 'alpine' with versions, expect three matches", 37 cmd: "search repo alpine --versions", 38 golden: "output/search-multiple-versions.txt", 39 }, { 40 name: "search for 'alpine' with version constraint, expect one match with version 0.1.0", 41 cmd: "search repo alpine --version '>= 0.1, < 0.2'", 42 golden: "output/search-constraint.txt", 43 }, { 44 name: "search for 'alpine' with version constraint, expect one match with version 0.1.0", 45 cmd: "search repo alpine --versions --version '>= 0.1, < 0.2'", 46 golden: "output/search-versions-constraint.txt", 47 }, { 48 name: "search for 'alpine' with version constraint, expect one match with version 0.2.0", 49 cmd: "search repo alpine --version '>= 0.1'", 50 golden: "output/search-constraint-single.txt", 51 }, { 52 name: "search for 'alpine' with version constraint and --versions, expect two matches", 53 cmd: "search repo alpine --versions --version '>= 0.1'", 54 golden: "output/search-multiple-versions-constraints.txt", 55 }, { 56 name: "search for 'syzygy', expect no matches", 57 cmd: "search repo syzygy", 58 golden: "output/search-not-found.txt", 59 }, { 60 name: "search for 'alp[a-z]+', expect two matches", 61 cmd: "search repo alp[a-z]+ --regexp", 62 golden: "output/search-regex.txt", 63 }, { 64 name: "search for 'alp[', expect failure to compile regexp", 65 cmd: "search repo alp[ --regexp", 66 wantError: true, 67 }} 68 69 settings.Debug = true 70 defer func() { settings.Debug = false }() 71 72 for i := range tests { 73 tests[i].cmd += " --repository-config " + repoFile 74 tests[i].cmd += " --repository-cache " + repoCache 75 } 76 runTestCmd(t, tests) 77 }