github.com/Racer159/helm-experiment@v0.0.0-20230822001441-1eb31183f614/src/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 cmd
    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 one match with latest stable version",
    29  		cmd:    "search repo alpine",
    30  		golden: "output/search-multiple-stable-release.txt",
    31  	}, {
    32  		name:   "search for 'alpine', expect one match with newest development version",
    33  		cmd:    "search repo alpine --devel",
    34  		golden: "output/search-multiple-devel-release.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  		name:   "search for 'maria', expect valid json output",
    69  		cmd:    "search repo maria --output json",
    70  		golden: "output/search-output-json.txt",
    71  	}, {
    72  		name:   "search for 'alpine', expect valid yaml output",
    73  		cmd:    "search repo alpine --output yaml",
    74  		golden: "output/search-output-yaml.txt",
    75  	}}
    76  
    77  	settings.Debug = true
    78  	defer func() { settings.Debug = false }()
    79  
    80  	for i := range tests {
    81  		tests[i].cmd += " --repository-config " + repoFile
    82  		tests[i].cmd += " --repository-cache " + repoCache
    83  	}
    84  	runTestCmd(t, tests)
    85  }
    86  
    87  func TestSearchRepoOutputCompletion(t *testing.T) {
    88  	outputFlagCompletionTest(t, "search repo")
    89  }
    90  
    91  func TestSearchRepoFileCompletion(t *testing.T) {
    92  	checkFileCompletion(t, "search repo", true) // File completion may be useful when inputting a keyword
    93  }