2fas-server/internal/common/db/error_test.go
Krzysztof Dryś e6bfee866a
fix: error handling in icons endpoints (first batch) (#16)
fix: error handling in icons endpoints (first batch)

Update error handling for some icons endpoints.
2023-11-28 12:52:56 +01:00

41 lines
721 B
Go

package db
import (
"fmt"
"testing"
)
func TestIsDBError(t *testing.T) {
tests := []struct {
name string
target error
isDBError bool
}{
{
name: "plain error",
target: fmt.Errorf("error"),
isDBError: false,
},
{
name: "wrapped error",
target: WrapError(fmt.Errorf("error")),
isDBError: true,
},
{
name: "error wrapped twice",
target: fmt.Errorf("error: %w", WrapError(fmt.Errorf("error"))),
isDBError: true,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
result := IsDBError(tc.target)
if tc.isDBError != result {
t.Fatalf("For %v, expected %v, got %v", tc.target, tc.isDBError, result)
}
})
}
}