github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/kubernetes/status/resource/status_test.go (about)

     1  /*
     2  Copyright 2019 The Skaffold 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 resource
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/GoogleContainerTools/skaffold/proto/v1"
    23  	"github.com/GoogleContainerTools/skaffold/testutil"
    24  )
    25  
    26  func TestString(t *testing.T) {
    27  	var tests = []struct {
    28  		description string
    29  		ae          *proto.ActionableErr
    30  		expected    string
    31  	}{
    32  		{
    33  			description: "should return error string if error is set",
    34  			ae:          &proto.ActionableErr{Message: "some error"},
    35  			expected:    "some error",
    36  		},
    37  		{
    38  			description: "should return error if both details and error are set",
    39  			ae:          &proto.ActionableErr{Message: "error happened due to something"},
    40  			expected:    "error happened due to something",
    41  		},
    42  		{
    43  			description: "should return empty string if all empty",
    44  			ae:          &proto.ActionableErr{},
    45  		},
    46  	}
    47  	for _, test := range tests {
    48  		testutil.Run(t, test.description, func(t *testutil.T) {
    49  			status := newStatus(test.ae)
    50  			t.CheckDeepEqual(test.expected, status.String())
    51  		})
    52  	}
    53  }
    54  
    55  func TestEqual(t *testing.T) {
    56  	var tests = []struct {
    57  		description string
    58  		old         Status
    59  		new         Status
    60  		expected    bool
    61  	}{
    62  		{
    63  			description: "status should be same if error messages are same",
    64  			old:         Status{ae: &proto.ActionableErr{ErrCode: 100, Message: "Waiting for 0/1 replicas to be available..."}},
    65  			new:         Status{ae: &proto.ActionableErr{ErrCode: 100, Message: "Waiting for 0/1 replicas to be available..."}},
    66  			expected:    true,
    67  		},
    68  		{
    69  			description: "status should be new if error is different",
    70  			old:         Status{ae: &proto.ActionableErr{}},
    71  			new:         Status{ae: &proto.ActionableErr{ErrCode: 100, Message: "see this error"}},
    72  		},
    73  		{
    74  			description: "status should be new if errcode are different but same message",
    75  			old:         Status{ae: &proto.ActionableErr{ErrCode: 100, Message: "see this error"}},
    76  			new:         Status{ae: &proto.ActionableErr{ErrCode: 101, Message: "see this error"}},
    77  		},
    78  		{
    79  			description: "status should be new if messages change",
    80  			old:         Status{ae: &proto.ActionableErr{ErrCode: 100, Message: "Waiting for 2/2 replicas to be available..."}},
    81  			new:         Status{ae: &proto.ActionableErr{ErrCode: 100, Message: "Waiting for 1/2 replicas to be available..."}},
    82  		},
    83  	}
    84  	for _, test := range tests {
    85  		testutil.Run(t, test.description, func(t *testutil.T) {
    86  			t.CheckDeepEqual(test.expected, test.old.Equal(test.new))
    87  		})
    88  	}
    89  }