github.com/lmittmann/w3@v0.20.0/internal/cmp.go (about) 1 package internal 2 3 import ( 4 "github.com/google/go-cmp/cmp" 5 ) 6 7 // EquateErrors returns a cmp.Option that can be used to compare errors by their string. 8 func EquateErrors() cmp.Option { 9 return cmp.FilterValues(areConcreteErrors, cmp.Comparer(compareErrors)) 10 } 11 12 func areConcreteErrors(x, y interface{}) bool { 13 _, ok1 := x.(error) 14 _, ok2 := y.(error) 15 return ok1 && ok2 16 } 17 18 func compareErrors(x, y interface{}) bool { 19 xe := x.(error) 20 ye := y.(error) 21 return xe == nil && ye == nil || xe != nil && ye != nil && xe.Error() == ye.Error() 22 }