k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/test/e2e/framework/expect_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 framework 18 19 import ( 20 "errors" 21 "testing" 22 23 "github.com/onsi/gomega" 24 "github.com/stretchr/testify/assert" 25 "github.com/stretchr/testify/require" 26 ) 27 28 // This test is sensitive to line numbering. 29 // The following lines can be removed to compensate for import changes. 30 // 31 // 32 // 33 // 34 // 35 // 36 // 37 // 38 // 39 // 40 // This must be line #40. 41 42 func TestNewGomega(t *testing.T) { 43 if err := Gomega().Expect("hello").To(gomega.Equal("hello")); err != nil { 44 t.Errorf("unexpected failure: %s", err.Error()) 45 } 46 err := Gomega().Expect("hello").ToNot(gomega.Equal("hello")) 47 require.NotNil(t, err) 48 assert.Equal(t, `Expected 49 <string>: hello 50 not to equal 51 <string>: hello`, err.Error()) 52 if !errors.Is(err, ErrFailure) { 53 t.Errorf("expected error that is ErrFailure, got %T: %+v", err, err) 54 } 55 var failure FailureError 56 if !errors.As(err, &failure) { 57 t.Errorf("expected error that can be copied to FailureError, got %T: %+v", err, err) 58 } else { 59 assert.Regexp(t, `^k8s.io/kubernetes/test/e2e/framework.TestNewGomega\(0x[0-9A-Fa-f]*\) 60 .*/test/e2e/framework/expect_test.go:46`, failure.Backtrace()) 61 } 62 }