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