github.com/umeshredd/helm@v3.0.0-alpha.1+incompatible/pkg/releasetesting/environment_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 releasetesting
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/pkg/errors"
    23  
    24  	"helm.sh/helm/pkg/release"
    25  )
    26  
    27  func TestCreateTestPodSuccess(t *testing.T) {
    28  	env := testEnvFixture()
    29  	test := testFixture()
    30  
    31  	if err := env.createTestPod(test); err != nil {
    32  		t.Errorf("Expected no error, got an error: %s", err)
    33  	}
    34  }
    35  
    36  func TestCreateTestPodFailure(t *testing.T) {
    37  	env := testEnvFixture()
    38  	env.KubeClient = &mockKubeClient{
    39  		err: errors.New("We ran out of budget and couldn't create finding-nemo"),
    40  	}
    41  	test := testFixture()
    42  
    43  	if err := env.createTestPod(test); err == nil {
    44  		t.Errorf("Expected error, got no error")
    45  	}
    46  	if test.result.Info == "" {
    47  		t.Errorf("Expected error to be saved in test result info but found empty string")
    48  	}
    49  	if test.result.Status != release.TestRunFailure {
    50  		t.Errorf("Expected test result status to be failure but got: %v", test.result.Status)
    51  	}
    52  }
    53  
    54  func TestStreamMessage(t *testing.T) {
    55  	env := testEnvFixture()
    56  	defer close(env.Messages)
    57  
    58  	expectedMessage := "testing streamMessage"
    59  	expectedStatus := release.TestRunSuccess
    60  	if err := env.streamMessage(expectedMessage, expectedStatus); err != nil {
    61  		t.Errorf("Expected no errors, got: %s", err)
    62  	}
    63  
    64  	got := <-env.Messages
    65  	if got.Msg != expectedMessage {
    66  		t.Errorf("Expected message: %s, got: %s", expectedMessage, got.Msg)
    67  	}
    68  	if got.Status != expectedStatus {
    69  		t.Errorf("Expected status: %v, got: %v", expectedStatus, got.Status)
    70  	}
    71  }