github.com/valdemarpavesi/helm@v2.9.1+incompatible/cmd/helm/list_test.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors All rights reserved.
     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  	"k8s.io/helm/pkg/proto/hapi/release"
    27  )
    28  
    29  func TestListCmd(t *testing.T) {
    30  	tests := []releaseCase{
    31  		{
    32  			name: "with a release",
    33  			rels: []*release.Release{
    34  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}),
    35  			},
    36  			expected: "thomas-guide",
    37  		},
    38  		{
    39  			name: "list",
    40  			rels: []*release.Release{
    41  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas"}),
    42  			},
    43  			expected: "NAME \tREVISION\tUPDATED                 \tSTATUS  \tCHART           \tNAMESPACE\natlas\t1       \t(.*)\tDEPLOYED\tfoo-0.1.0-beta.1\tdefault  \n",
    44  		},
    45  		{
    46  			name:  "list, one deployed, one failed",
    47  			flags: []string{"-q"},
    48  			rels: []*release.Release{
    49  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_FAILED}),
    50  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
    51  			},
    52  			expected: "thomas-guide\natlas-guide",
    53  		},
    54  		{
    55  			name:  "with a release, multiple flags",
    56  			flags: []string{"--deleted", "--deployed", "--failed", "-q"},
    57  			rels: []*release.Release{
    58  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_DELETED}),
    59  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
    60  			},
    61  			// Note: We're really only testing that the flags parsed correctly. Which results are returned
    62  			// depends on the backend. And until pkg/helm is done, we can't mock this.
    63  			expected: "thomas-guide\natlas-guide",
    64  		},
    65  		{
    66  			name:  "with a release, multiple flags",
    67  			flags: []string{"--all", "-q"},
    68  			rels: []*release.Release{
    69  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_DELETED}),
    70  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
    71  			},
    72  			// See note on previous test.
    73  			expected: "thomas-guide\natlas-guide",
    74  		},
    75  		{
    76  			name:  "with a release, multiple flags, deleting",
    77  			flags: []string{"--all", "-q"},
    78  			rels: []*release.Release{
    79  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_DELETING}),
    80  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
    81  			},
    82  			// See note on previous test.
    83  			expected: "thomas-guide\natlas-guide",
    84  		},
    85  		{
    86  			name:  "namespace defined, multiple flags",
    87  			flags: []string{"--all", "-q", "--namespace test123"},
    88  			rels: []*release.Release{
    89  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Namespace: "test123"}),
    90  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Namespace: "test321"}),
    91  			},
    92  			// See note on previous test.
    93  			expected: "thomas-guide",
    94  		},
    95  		{
    96  			name:  "with a pending release, multiple flags",
    97  			flags: []string{"--all", "-q"},
    98  			rels: []*release.Release{
    99  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_PENDING_INSTALL}),
   100  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
   101  			},
   102  			expected: "thomas-guide\natlas-guide",
   103  		},
   104  		{
   105  			name:  "with a pending release, pending flag",
   106  			flags: []string{"--pending", "-q"},
   107  			rels: []*release.Release{
   108  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_PENDING_INSTALL}),
   109  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "wild-idea", StatusCode: release.Status_PENDING_UPGRADE}),
   110  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "crazy-maps", StatusCode: release.Status_PENDING_ROLLBACK}),
   111  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
   112  			},
   113  			expected: "thomas-guide\nwild-idea\ncrazy-maps",
   114  		},
   115  		{
   116  			name: "with old releases",
   117  			rels: []*release.Release{
   118  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}),
   119  				helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_FAILED}),
   120  			},
   121  			expected: "thomas-guide",
   122  		},
   123  	}
   124  
   125  	runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
   126  		return newListCmd(c, out)
   127  	})
   128  }