db_test.go 758 B

1234567891011121314151617181920212223242526272829303132
  1. package acme
  2. import (
  3. "database/sql"
  4. "errors"
  5. "fmt"
  6. "testing"
  7. )
  8. func TestIsErrNotFound(t *testing.T) {
  9. type args struct {
  10. err error
  11. }
  12. tests := []struct {
  13. name string
  14. args args
  15. want bool
  16. }{
  17. {"true ErrNotFound", args{ErrNotFound}, true},
  18. {"true sql.ErrNoRows", args{sql.ErrNoRows}, true},
  19. {"true wrapped ErrNotFound", args{fmt.Errorf("something failed: %w", ErrNotFound)}, true},
  20. {"true wrapped sql.ErrNoRows", args{fmt.Errorf("something failed: %w", sql.ErrNoRows)}, true},
  21. {"false other", args{errors.New("not found")}, false},
  22. }
  23. for _, tt := range tests {
  24. t.Run(tt.name, func(t *testing.T) {
  25. if got := IsErrNotFound(tt.args.err); got != tt.want {
  26. t.Errorf("IsErrNotFound() = %v, want %v", got, tt.want)
  27. }
  28. })
  29. }
  30. }