|
| 1 | +# run ginkgolinter to find wrong error assertions |
| 2 | +! exec ginkgolinter errassertion |
| 3 | +! stdout . |
| 4 | +stderr -count=1 'Success matcher only support a single error value, or function with Gomega as its first parameter' |
| 5 | +stderr -count=1 'wrong error assertion.' |
| 6 | +stderr -count=1 'Success matcher does not support multiple values' |
| 7 | + |
| 8 | +# also enable the force succeed rule |
| 9 | +! exec ginkgolinter --force-succeed=true errassertion |
| 10 | +! stdout . |
| 11 | +stderr -count=1 'Success matcher only support a single error value, or function with Gomega as its first parameter' |
| 12 | +stderr -count=1 'wrong error assertion.' |
| 13 | +stderr -count=1 'Success matcher does not support multiple values' |
| 14 | +stderr -count=1 'prefer using the HaveOccurred matcher for non-function error value, instead of Succeed' |
| 15 | +stderr -count=1 'prefer using the Succeed matcher for error function, instead of HaveOccurred.' |
| 16 | + |
| 17 | +# run with -fix, expect wrong error assertion errors |
| 18 | +! exec ginkgolinter --fix --force-succeed=true errassertion |
| 19 | +! stdout . |
| 20 | +stderr -count=1 'Success matcher only support a single error value, or function with Gomega as its first parameter' |
| 21 | +stderr -count=1 'wrong error assertion.' |
| 22 | +stderr -count=1 'Success matcher does not support multiple values' |
| 23 | +stderr -count=1 'prefer using the HaveOccurred matcher for non-function error value, instead of Succeed' |
| 24 | +stderr -count=1 'prefer using the Succeed matcher for error function, instead of HaveOccurred.' |
| 25 | + |
| 26 | +# run again after fix, expect only non-fixable errors |
| 27 | +! exec ginkgolinter errassertion |
| 28 | +! stdout . |
| 29 | +stderr -count=1 'Success matcher only support a single error value, or function with Gomega as its first parameter' |
| 30 | +! stderr 'wrong error assertion.' |
| 31 | +stderr -count=1 'Success matcher does not support multiple values' |
| 32 | +! stderr 'prefer using the HaveOccurred matcher for non-function error value, instead of Succeed' |
| 33 | +! stderr 'prefer using the Succeed matcher for error function, instead of HaveOccurred.' |
| 34 | + |
| 35 | +-- err.go -- |
| 36 | +package errassertion |
| 37 | + |
| 38 | +import ( |
| 39 | + "errors" |
| 40 | + |
| 41 | + . "github.com/onsi/ginkgo/v2" |
| 42 | + . "github.com/onsi/gomega" |
| 43 | +) |
| 44 | + |
| 45 | +var _ = Describe("check error assertion", func() { |
| 46 | + It("should not comparing ee to nil", func() { |
| 47 | + err := errors.New("error") |
| 48 | + Eventually(func() string{return "not error"}).Should(Succeed()) |
| 49 | + Eventually(func() error{return err}).Should(BeNil()) |
| 50 | + Eventually(func() (int, error) {return 42, nil}).Should(Succeed()) |
| 51 | + Eventually(func() error {return err}).Should(HaveOccurred()) |
| 52 | + Expect(err).ToNot(Succeed()) |
| 53 | + Expect(func() error {return err}()).To(HaveOccurred()) |
| 54 | + }) |
| 55 | +}) |
| 56 | + |
| 57 | +-- go.mod -- |
| 58 | +module errassertion |
| 59 | + |
| 60 | +go 1.22 |
| 61 | + |
| 62 | +require ( |
| 63 | + github.com/onsi/ginkgo/v2 v2.13.2 |
| 64 | + github.com/onsi/gomega v1.30.0 |
| 65 | +) |
| 66 | + |
| 67 | +require ( |
| 68 | + github.com/go-logr/logr v1.3.0 // indirect |
| 69 | + github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect |
| 70 | + github.com/google/go-cmp v0.6.0 // indirect |
| 71 | + github.com/google/pprof v0.0.0-20231212022811-ec68065c825e // indirect |
| 72 | + golang.org/x/net v0.19.0 // indirect |
| 73 | + golang.org/x/sys v0.15.0 // indirect |
| 74 | + golang.org/x/text v0.14.0 // indirect |
| 75 | + golang.org/x/tools v0.16.1 // indirect |
| 76 | + gopkg.in/yaml.v3 v3.0.1 // indirect |
| 77 | +) |
| 78 | + |
| 79 | +-- go.sum -- |
| 80 | +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
| 81 | +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= |
| 82 | +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
| 83 | +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= |
| 84 | +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= |
| 85 | +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= |
| 86 | +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= |
| 87 | +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= |
| 88 | +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= |
| 89 | +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= |
| 90 | +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= |
| 91 | +github.com/google/pprof v0.0.0-20231212022811-ec68065c825e h1:bwOy7hAFd0C91URzMIEBfr6BAz29yk7Qj0cy6S7DJlU= |
| 92 | +github.com/google/pprof v0.0.0-20231212022811-ec68065c825e/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= |
| 93 | +github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs= |
| 94 | +github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= |
| 95 | +github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= |
| 96 | +github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= |
| 97 | +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= |
| 98 | +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
| 99 | +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= |
| 100 | +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= |
| 101 | +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= |
| 102 | +golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= |
| 103 | +golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= |
| 104 | +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= |
| 105 | +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= |
| 106 | +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= |
| 107 | +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= |
| 108 | +golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA= |
| 109 | +golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= |
| 110 | +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= |
| 111 | +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= |
| 112 | +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= |
| 113 | +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
| 114 | +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
| 115 | +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= |
| 116 | +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
0 commit comments