github.com/codefresh-io/kcfi@v0.0.0-20230301195427-c1578715cc46/cmd/kcfi/list_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  	"helm.sh/helm/v3/pkg/chart"
    23  	"helm.sh/helm/v3/pkg/release"
    24  	"helm.sh/helm/v3/pkg/time"
    25  )
    26  
    27  func TestListCmd(t *testing.T) {
    28  	defaultNamespace := "default"
    29  
    30  	sampleTimeSeconds := int64(1452902400)
    31  	timestamp1 := time.Unix(sampleTimeSeconds+1, 0).UTC()
    32  	timestamp2 := time.Unix(sampleTimeSeconds+2, 0).UTC()
    33  	timestamp3 := time.Unix(sampleTimeSeconds+3, 0).UTC()
    34  	timestamp4 := time.Unix(sampleTimeSeconds+4, 0).UTC()
    35  	chartInfo := &chart.Chart{
    36  		Metadata: &chart.Metadata{
    37  			Name:       "chickadee",
    38  			Version:    "1.0.0",
    39  			AppVersion: "0.0.1",
    40  		},
    41  	}
    42  
    43  	releaseFixture := []*release.Release{
    44  		{
    45  			Name:      "starlord",
    46  			Version:   1,
    47  			Namespace: defaultNamespace,
    48  			Info: &release.Info{
    49  				LastDeployed: timestamp1,
    50  				Status:       release.StatusSuperseded,
    51  			},
    52  			Chart: chartInfo,
    53  		},
    54  		{
    55  			Name:      "starlord",
    56  			Version:   2,
    57  			Namespace: defaultNamespace,
    58  			Info: &release.Info{
    59  				LastDeployed: timestamp1,
    60  				Status:       release.StatusDeployed,
    61  			},
    62  			Chart: chartInfo,
    63  		},
    64  		{
    65  			Name:      "groot",
    66  			Version:   1,
    67  			Namespace: defaultNamespace,
    68  			Info: &release.Info{
    69  				LastDeployed: timestamp1,
    70  				Status:       release.StatusUninstalled,
    71  			},
    72  			Chart: chartInfo,
    73  		},
    74  		{
    75  			Name:      "gamora",
    76  			Version:   1,
    77  			Namespace: defaultNamespace,
    78  			Info: &release.Info{
    79  				LastDeployed: timestamp1,
    80  				Status:       release.StatusSuperseded,
    81  			},
    82  			Chart: chartInfo,
    83  		},
    84  		{
    85  			Name:      "rocket",
    86  			Version:   1,
    87  			Namespace: defaultNamespace,
    88  			Info: &release.Info{
    89  				LastDeployed: timestamp2,
    90  				Status:       release.StatusFailed,
    91  			},
    92  			Chart: chartInfo,
    93  		},
    94  		{
    95  			Name:      "drax",
    96  			Version:   1,
    97  			Namespace: defaultNamespace,
    98  			Info: &release.Info{
    99  				LastDeployed: timestamp1,
   100  				Status:       release.StatusUninstalling,
   101  			},
   102  			Chart: chartInfo,
   103  		},
   104  		{
   105  			Name:      "thanos",
   106  			Version:   1,
   107  			Namespace: defaultNamespace,
   108  			Info: &release.Info{
   109  				LastDeployed: timestamp1,
   110  				Status:       release.StatusPendingInstall,
   111  			},
   112  			Chart: chartInfo,
   113  		},
   114  		{
   115  			Name:      "hummingbird",
   116  			Version:   1,
   117  			Namespace: defaultNamespace,
   118  			Info: &release.Info{
   119  				LastDeployed: timestamp3,
   120  				Status:       release.StatusDeployed,
   121  			},
   122  			Chart: chartInfo,
   123  		},
   124  		{
   125  			Name:      "iguana",
   126  			Version:   2,
   127  			Namespace: defaultNamespace,
   128  			Info: &release.Info{
   129  				LastDeployed: timestamp4,
   130  				Status:       release.StatusDeployed,
   131  			},
   132  			Chart: chartInfo,
   133  		},
   134  		{
   135  			Name:      "starlord",
   136  			Version:   2,
   137  			Namespace: "milano",
   138  			Info: &release.Info{
   139  				LastDeployed: timestamp1,
   140  				Status:       release.StatusDeployed,
   141  			},
   142  			Chart: chartInfo,
   143  		},
   144  	}
   145  
   146  	tests := []cmdTestCase{{
   147  		name:   "list releases",
   148  		cmd:    "list",
   149  		golden: "output/list.txt",
   150  		rels:   releaseFixture,
   151  	}, {
   152  		name:   "list all releases",
   153  		cmd:    "list --all",
   154  		golden: "output/list-all.txt",
   155  		rels:   releaseFixture,
   156  	}, {
   157  		name:   "list releases sorted by release date",
   158  		cmd:    "list --date",
   159  		golden: "output/list-date.txt",
   160  		rels:   releaseFixture,
   161  	}, {
   162  		name:   "list failed releases",
   163  		cmd:    "list --failed",
   164  		golden: "output/list-failed.txt",
   165  		rels:   releaseFixture,
   166  	}, {
   167  		name:   "list filtered releases",
   168  		cmd:    "list --filter='.*'",
   169  		golden: "output/list-filter.txt",
   170  		rels:   releaseFixture,
   171  	}, {
   172  		name:   "list releases, limited to one release",
   173  		cmd:    "list --max 1",
   174  		golden: "output/list-max.txt",
   175  		rels:   releaseFixture,
   176  	}, {
   177  		name:   "list releases, offset by one",
   178  		cmd:    "list --offset 1",
   179  		golden: "output/list-offset.txt",
   180  		rels:   releaseFixture,
   181  	}, {
   182  		name:   "list pending releases",
   183  		cmd:    "list --pending",
   184  		golden: "output/list-pending.txt",
   185  		rels:   releaseFixture,
   186  	}, {
   187  		name:   "list releases in reverse order",
   188  		cmd:    "list --reverse",
   189  		golden: "output/list-reverse.txt",
   190  		rels:   releaseFixture,
   191  	}, {
   192  		name:   "list releases sorted by reversed release date",
   193  		cmd:    "list --date --reverse",
   194  		golden: "output/list-date-reversed.txt",
   195  		rels:   releaseFixture,
   196  	}, {
   197  		name:   "list releases in short output format",
   198  		cmd:    "list --short",
   199  		golden: "output/list-short.txt",
   200  		rels:   releaseFixture,
   201  	}, {
   202  		name:   "list releases in short output format",
   203  		cmd:    "list --short --output yaml",
   204  		golden: "output/list-short-yaml.txt",
   205  		rels:   releaseFixture,
   206  	}, {
   207  		name:   "list releases in short output format",
   208  		cmd:    "list --short --output json",
   209  		golden: "output/list-short-json.txt",
   210  		rels:   releaseFixture,
   211  	}, {
   212  		name:   "list superseded releases",
   213  		cmd:    "list --superseded",
   214  		golden: "output/list-superseded.txt",
   215  		rels:   releaseFixture,
   216  	}, {
   217  		name:   "list uninstalled releases",
   218  		cmd:    "list --uninstalled",
   219  		golden: "output/list-uninstalled.txt",
   220  		rels:   releaseFixture,
   221  	}, {
   222  		name:   "list releases currently uninstalling",
   223  		cmd:    "list --uninstalling",
   224  		golden: "output/list-uninstalling.txt",
   225  		rels:   releaseFixture,
   226  	}, {
   227  		name:   "list releases in another namespace",
   228  		cmd:    "list -n milano",
   229  		golden: "output/list-namespace.txt",
   230  		rels:   releaseFixture,
   231  	}}
   232  	runTestCmd(t, tests)
   233  }
   234  
   235  func TestListOutputCompletion(t *testing.T) {
   236  	outputFlagCompletionTest(t, "list")
   237  }