k8s.io/kubernetes@v1.29.3/pkg/probe/exec/errors_test.go (about) 1 /* 2 Copyright 2023 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 exec 18 19 import ( 20 "errors" 21 "testing" 22 "time" 23 ) 24 25 func TestErrors(t *testing.T) { 26 tests := []struct { 27 err error 28 timeout time.Duration 29 message string 30 }{ 31 { 32 err: errors.New("some error message"), 33 timeout: time.Hour * 8, 34 message: "some error message", 35 }, 36 } 37 38 for i, test := range tests { 39 testErr := NewTimeoutError(test.err, test.timeout) 40 41 if testErr == nil { 42 t.Errorf("[%d] expected error a TimeoutError, got nil", i) 43 } 44 if msg := testErr.Error(); msg != test.message { 45 t.Errorf("[%d] expected error message %q, got %q", i, test.message, msg) 46 } 47 if timeout := testErr.Timeout(); timeout != test.timeout { 48 t.Errorf("[%d] expected timeout %q, got %q", i, test.timeout, timeout) 49 } 50 } 51 }