github.com/uhthomas/helm@v3.0.0-beta.3+incompatible/cmd/helm/status_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  	"time"
    22  
    23  	"helm.sh/helm/pkg/chart"
    24  	"helm.sh/helm/pkg/release"
    25  )
    26  
    27  func TestStatusCmd(t *testing.T) {
    28  	releasesMockWithStatus := func(info *release.Info, hooks ...*release.Hook) []*release.Release {
    29  		info.LastDeployed = time.Unix(1452902400, 0).UTC()
    30  		return []*release.Release{{
    31  			Name:      "flummoxed-chickadee",
    32  			Namespace: "default",
    33  			Info:      info,
    34  			Chart:     &chart.Chart{},
    35  			Hooks:     hooks,
    36  		}}
    37  	}
    38  
    39  	tests := []cmdTestCase{{
    40  		name:   "get status of a deployed release",
    41  		cmd:    "status flummoxed-chickadee",
    42  		golden: "output/status.txt",
    43  		rels: releasesMockWithStatus(&release.Info{
    44  			Status: release.StatusDeployed,
    45  		}),
    46  	}, {
    47  		name:   "get status of a deployed release with notes",
    48  		cmd:    "status flummoxed-chickadee",
    49  		golden: "output/status-with-notes.txt",
    50  		rels: releasesMockWithStatus(&release.Info{
    51  			Status: release.StatusDeployed,
    52  			Notes:  "release notes",
    53  		}),
    54  	}, {
    55  		name:   "get status of a deployed release with notes in json",
    56  		cmd:    "status flummoxed-chickadee -o json",
    57  		golden: "output/status.json",
    58  		rels: releasesMockWithStatus(&release.Info{
    59  			Status: release.StatusDeployed,
    60  			Notes:  "release notes",
    61  		}),
    62  	}, {
    63  		name:   "get status of a deployed release with test suite",
    64  		cmd:    "status flummoxed-chickadee",
    65  		golden: "output/status-with-test-suite.txt",
    66  		rels: releasesMockWithStatus(
    67  			&release.Info{
    68  				Status: release.StatusDeployed,
    69  			},
    70  			&release.Hook{
    71  				Name:   "never-run-test",
    72  				Events: []release.HookEvent{release.HookTest},
    73  			},
    74  			&release.Hook{
    75  				Name:   "passing-test",
    76  				Events: []release.HookEvent{release.HookTest},
    77  				LastRun: release.HookExecution{
    78  					StartedAt:   mustParseTime("2006-01-02T15:04:05Z"),
    79  					CompletedAt: mustParseTime("2006-01-02T15:04:07Z"),
    80  					Phase:       release.HookPhaseSucceeded,
    81  				},
    82  			},
    83  			&release.Hook{
    84  				Name:   "failing-test",
    85  				Events: []release.HookEvent{release.HookTest},
    86  				LastRun: release.HookExecution{
    87  					StartedAt:   mustParseTime("2006-01-02T15:10:05Z"),
    88  					CompletedAt: mustParseTime("2006-01-02T15:10:07Z"),
    89  					Phase:       release.HookPhaseFailed,
    90  				},
    91  			},
    92  			&release.Hook{
    93  				Name:   "passing-pre-install",
    94  				Events: []release.HookEvent{release.HookPreInstall},
    95  				LastRun: release.HookExecution{
    96  					StartedAt:   mustParseTime("2006-01-02T15:00:05Z"),
    97  					CompletedAt: mustParseTime("2006-01-02T15:00:07Z"),
    98  					Phase:       release.HookPhaseSucceeded,
    99  				},
   100  			},
   101  		),
   102  	}}
   103  	runTestCmd(t, tests)
   104  }
   105  
   106  func mustParseTime(t string) time.Time {
   107  	res, _ := time.Parse(time.RFC3339, t)
   108  	return res
   109  }