github.com/vtuson/helm@v2.8.2+incompatible/cmd/helm/release_testing_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  	"bytes"
    21  	"testing"
    22  
    23  	"k8s.io/helm/pkg/helm"
    24  	"k8s.io/helm/pkg/proto/hapi/release"
    25  )
    26  
    27  func TestReleaseTesting(t *testing.T) {
    28  	tests := []struct {
    29  		name      string
    30  		args      []string
    31  		flags     []string
    32  		responses map[string]release.TestRun_Status
    33  		fail      bool
    34  	}{
    35  		{
    36  			name:      "basic test",
    37  			args:      []string{"example-release"},
    38  			flags:     []string{},
    39  			responses: map[string]release.TestRun_Status{"PASSED: green lights everywhere": release.TestRun_SUCCESS},
    40  			fail:      false,
    41  		},
    42  		{
    43  			name:      "test failure",
    44  			args:      []string{"example-fail"},
    45  			flags:     []string{},
    46  			responses: map[string]release.TestRun_Status{"FAILURE: red lights everywhere": release.TestRun_FAILURE},
    47  			fail:      true,
    48  		},
    49  		{
    50  			name:      "test unknown",
    51  			args:      []string{"example-unknown"},
    52  			flags:     []string{},
    53  			responses: map[string]release.TestRun_Status{"UNKNOWN: yellow lights everywhere": release.TestRun_UNKNOWN},
    54  			fail:      false,
    55  		},
    56  		{
    57  			name:      "test error",
    58  			args:      []string{"example-error"},
    59  			flags:     []string{},
    60  			responses: map[string]release.TestRun_Status{"ERROR: yellow lights everywhere": release.TestRun_FAILURE},
    61  			fail:      true,
    62  		},
    63  		{
    64  			name:      "test running",
    65  			args:      []string{"example-running"},
    66  			flags:     []string{},
    67  			responses: map[string]release.TestRun_Status{"RUNNING: things are happpeningggg": release.TestRun_RUNNING},
    68  			fail:      false,
    69  		},
    70  		{
    71  			name:  "multiple tests example",
    72  			args:  []string{"example-suite"},
    73  			flags: []string{},
    74  			responses: map[string]release.TestRun_Status{
    75  				"RUNNING: things are happpeningggg":           release.TestRun_RUNNING,
    76  				"PASSED: party time":                          release.TestRun_SUCCESS,
    77  				"RUNNING: things are happening again":         release.TestRun_RUNNING,
    78  				"FAILURE: good thing u checked :)":            release.TestRun_FAILURE,
    79  				"RUNNING: things are happpeningggg yet again": release.TestRun_RUNNING,
    80  				"PASSED: feel free to party again":            release.TestRun_SUCCESS},
    81  			fail: true,
    82  		},
    83  	}
    84  
    85  	for _, tt := range tests {
    86  		c := &helm.FakeClient{Responses: tt.responses}
    87  
    88  		buf := bytes.NewBuffer(nil)
    89  		cmd := newReleaseTestCmd(c, buf)
    90  		cmd.ParseFlags(tt.flags)
    91  
    92  		err := cmd.RunE(cmd, tt.args)
    93  		if err == nil && tt.fail {
    94  			t.Errorf("%q did not fail but should have failed", tt.name)
    95  		}
    96  
    97  		if err != nil {
    98  			if tt.fail {
    99  				continue
   100  			} else {
   101  				t.Errorf("%q reported error: %s", tt.name, err)
   102  			}
   103  		}
   104  
   105  	}
   106  }