github.com/verrazzano/verrazzano@v1.7.0/tools/eventually-checker/testdata/main.go (about) 1 // Copyright (c) 2021, 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 package main 4 5 import ( 6 "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework" 7 "github.com/verrazzano/verrazzano/tools/eventually-checker/testdata/internal" 8 9 . "github.com/onsi/ginkgo/v2" //nolint 10 . "github.com/onsi/gomega" //nolint 11 ) 12 13 type testStruct struct { 14 } 15 16 func (t *testStruct) PointerReceiverThatCallsExpect() error { 17 Expect(false).To(BeTrue()) 18 return nil 19 } 20 21 func (t testStruct) ValueReceiverThatCallsExpect() error { 22 Expect(false).To(BeTrue()) 23 return nil 24 } 25 26 var ts testStruct 27 28 var t = framework.NewTestFramework("main") 29 30 func main() { 31 It("Test 1", func() { 32 Eventually(func() (bool, error) { 33 localFunc() 34 return internal.DoSomething() 35 }) 36 37 Expect(false).To(BeTrue()) 38 }) 39 40 It("Test 2", func() { 41 Eventually(eventuallyFunc) 42 }) 43 44 It("Test 3", func() { 45 Eventually(internal.AnotherFunc) 46 }) 47 48 It("Test 4", func() { 49 Eventually(func() error { 50 return ts.PointerReceiverThatCallsExpect() 51 }) 52 }) 53 54 It("Test 5", func() { 55 Eventually(func() error { 56 return ts.ValueReceiverThatCallsExpect() 57 }) 58 }) 59 } 60 61 func eventuallyFunc() bool { 62 Fail("FAIL!") 63 return true 64 } 65 66 func unusedFunc() { //nolint 67 internal.DoSomething() 68 } 69 70 func localFunc() { 71 } 72 73 // this common Ginkgo pattern is here to test a bug fix... prior to the fix, the "Fail" 74 // here would be associated with the preceding function declaration ("localFunc" in this 75 // case) and it would cause a false positive 76 var _ = Describe("Generic decl bug fix", func() { 77 Fail("This is not in an eventually") 78 }) 79 80 // Tests for the Ginkgo wrapped functions 81 var _ = t.Describe("Wrapper for the Ginkgo Describe node", func() { 82 t.It("Test 6", func() { 83 Eventually(func() (bool, error) { 84 return true, nil 85 }) 86 }) 87 88 t.It("Test 7, sample test with Expect inside Eventually", func() { 89 Eventually(func() (bool, error) { 90 // Linter should catch this as an issue 91 Expect(true).To(BeTrue()) 92 return true, nil 93 }) 94 }) 95 96 t.It("Test 8, sample test with Fail inside Eventually", func() { 97 Eventually(func() (bool, error) { 98 // Linter should catch this as an issue 99 Fail("There is a failure") 100 return true, nil 101 }) 102 }) 103 104 t.It("Test 9, the function called from Eventually has Expect inside it", func() { 105 Eventually(func() (bool, error) { 106 return internal.DoCallExpect(), nil 107 }) 108 109 Expect(false).To(BeTrue()) 110 }) 111 112 t.It("Test 10, call a function having Eventually has Expect inside it", func() { 113 internal.DoCallEventually() 114 }) 115 116 // The following calls are good 117 Expect(true).To(BeTrue()) 118 Fail("This Fail is not in an eventually") 119 })