sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/plank/error_test.go (about)

     1  /*
     2  Copyright 2020 The Kubernetes 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 plank
    18  
    19  import (
    20  	"errors"
    21  	"testing"
    22  )
    23  
    24  func TestTerminalError(t *testing.T) {
    25  	tests := []struct {
    26  		name       string
    27  		gotErr     error
    28  		isTerminal bool
    29  	}{
    30  		{
    31  			name:       "nil",
    32  			gotErr:     TerminalError(nil),
    33  			isTerminal: true,
    34  		},
    35  		{
    36  			name:       "wrap error",
    37  			gotErr:     TerminalError(errors.New("ramdom error")),
    38  			isTerminal: true,
    39  		},
    40  		{
    41  			name:       "not nil",
    42  			gotErr:     nil,
    43  			isTerminal: false,
    44  		},
    45  		{
    46  			name:       "not random error",
    47  			gotErr:     errors.New("random error"),
    48  			isTerminal: false,
    49  		},
    50  	}
    51  
    52  	for _, tt := range tests {
    53  		t.Run(tt.name, func(t *testing.T) {
    54  			got, want := IsTerminalError(tt.gotErr), tt.isTerminal
    55  			if got != want {
    56  				t.Fatalf("Error matching not expected. want match: %v. got match: %v", want, got)
    57  			}
    58  		})
    59  	}
    60  }