Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions contract/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ import (
)

func TestErrCacheKeyNotFoundMessage(t *testing.T) {
t.Parallel()

require.Equal(t, "cache key not found", contract.ErrCacheKeyNotFound.Error())
}

func TestErrCacheKeyNotFoundIsNonNil(t *testing.T) {
t.Parallel()

require.NotNil(t, contract.ErrCacheKeyNotFound)
}

func TestErrCacheUnsupportedOperationMessage(t *testing.T) {
t.Parallel()

require.Equal(
t,
"cache unsupported operation",
Expand All @@ -24,5 +30,7 @@ func TestErrCacheUnsupportedOperationMessage(t *testing.T) {
}

func TestErrCacheUnsupportedOperationIsNonNil(t *testing.T) {
t.Parallel()

require.NotNil(t, contract.ErrCacheUnsupportedOperation)
}
2 changes: 1 addition & 1 deletion contract/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ type Database interface {
// WithTransaction executes the provided function fn within a database transaction.
// If fn returns an error, the transaction is rolled back. Otherwise, it is committed.
// The tx passed to fn implements the same Database interface and can be used
// for nested operations within the transaction.
// for operations within the transaction scope.
WithTransaction(ctx context.Context, fn func(tx Database) error) error
}
8 changes: 8 additions & 0 deletions contract/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
)

func TestErrDatabaseNoRowsMessage(t *testing.T) {
t.Parallel()

require.Equal(
t,
"no database rows were found",
Expand All @@ -16,10 +18,14 @@ func TestErrDatabaseNoRowsMessage(t *testing.T) {
}

func TestErrDatabaseNoRowsIsNonNil(t *testing.T) {
t.Parallel()

require.NotNil(t, contract.ErrDatabaseNoRows)
}

func TestErrDatabaseNestedTransactionMessage(t *testing.T) {
t.Parallel()

require.Equal(
t,
"nested transactions are not supported",
Expand All @@ -28,5 +34,7 @@ func TestErrDatabaseNestedTransactionMessage(t *testing.T) {
}

func TestErrDatabaseNestedTransactionIsNonNil(t *testing.T) {
t.Parallel()

require.NotNil(t, contract.ErrDatabaseNestedTransaction)
}
3 changes: 3 additions & 0 deletions contract/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ type Hasher interface {
// different parameters than the current configuration, indicating the value
// should be re-hashed on the next successful authentication.
type Rehashable interface {
// NeedsRehash reports whether the given hash was produced with
// different parameters than the current configuration, indicating
// the value should be re-hashed.
NeedsRehash(hash []byte) bool
}
4 changes: 4 additions & 0 deletions contract/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import (
)

func TestHooksKeyIsNonNil(t *testing.T) {
t.Parallel()

require.NotNil(t, contract.HooksKey)
}

func TestHooksKeyIsDistinctType(t *testing.T) {
t.Parallel()

var other any = struct{}{}

require.NotEqual(t, other, contract.HooksKey)
Expand Down
58 changes: 58 additions & 0 deletions contract/request/body_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
)

func TestBytesReadsEntireBody(t *testing.T) {
t.Parallel()

body := "hello world"
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))

Expand All @@ -23,6 +25,8 @@ func TestBytesReadsEntireBody(t *testing.T) {
}

func TestBytesEmptyBody(t *testing.T) {
t.Parallel()

r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))

result, err := request.Bytes(r)
Expand All @@ -32,6 +36,8 @@ func TestBytesEmptyBody(t *testing.T) {
}

func TestBytesErrorOnFailedRead(t *testing.T) {
t.Parallel()

r := httptest.NewRequest(http.MethodPost, "/", errReader{})

_, err := request.Bytes(r)
Expand All @@ -51,6 +57,8 @@ func TestLimitedBytesReturnsErrorWhenBodyExceedsLimit(t *testing.T) {
}

func TestLimitedBytesReadsFullBodyUnderLimit(t *testing.T) {
t.Parallel()

body := "abc"
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))

Expand All @@ -61,6 +69,8 @@ func TestLimitedBytesReadsFullBodyUnderLimit(t *testing.T) {
}

func TestLimitedBytesUsesDefaultOnNegativeMaxSize(t *testing.T) {
t.Parallel()

body := "short"
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))

Expand All @@ -71,6 +81,8 @@ func TestLimitedBytesUsesDefaultOnNegativeMaxSize(t *testing.T) {
}

func TestStringReadsBodyAsString(t *testing.T) {
t.Parallel()

body := "hello string"
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))

Expand All @@ -81,6 +93,8 @@ func TestStringReadsBodyAsString(t *testing.T) {
}

func TestStringEmptyBody(t *testing.T) {
t.Parallel()

r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))

result, err := request.String(r)
Expand All @@ -90,6 +104,8 @@ func TestStringEmptyBody(t *testing.T) {
}

func TestStringErrorOnFailedRead(t *testing.T) {
t.Parallel()

r := httptest.NewRequest(http.MethodPost, "/", errReader{})

_, err := request.String(r)
Expand All @@ -109,6 +125,8 @@ func TestLimitedStringReturnsErrorWhenBodyExceedsLimit(t *testing.T) {
}

func TestLimitedStringReadsFullBodyUnderLimit(t *testing.T) {
t.Parallel()

body := "abc"
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))

Expand All @@ -119,6 +137,8 @@ func TestLimitedStringReadsFullBodyUnderLimit(t *testing.T) {
}

func TestLimitedStringUsesDefaultOnNegativeMaxSize(t *testing.T) {
t.Parallel()

body := "short"
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))

Expand All @@ -129,6 +149,8 @@ func TestLimitedStringUsesDefaultOnNegativeMaxSize(t *testing.T) {
}

func TestLimitedStringErrorOnFailedRead(t *testing.T) {
t.Parallel()

r := httptest.NewRequest(http.MethodPost, "/", errReader{})

_, err := request.LimitedString(r, 10)
Expand All @@ -137,6 +159,8 @@ func TestLimitedStringErrorOnFailedRead(t *testing.T) {
}

func TestJSONDecodesValidPayload(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
Age int `json:"age"`
Expand All @@ -155,6 +179,8 @@ func TestJSONDecodesValidPayload(t *testing.T) {
}

func TestJSONReturnsErrorOnInvalidPayload(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
}
Expand All @@ -170,6 +196,8 @@ func TestJSONReturnsErrorOnInvalidPayload(t *testing.T) {
}

func TestJSONIgnoresUnknownFields(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
}
Expand All @@ -186,6 +214,8 @@ func TestJSONIgnoresUnknownFields(t *testing.T) {
}

func TestStrictJSONDecodesValidPayload(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
}
Expand All @@ -202,6 +232,8 @@ func TestStrictJSONDecodesValidPayload(t *testing.T) {
}

func TestStrictJSONRejectsUnknownFields(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
}
Expand All @@ -217,6 +249,8 @@ func TestStrictJSONRejectsUnknownFields(t *testing.T) {
}

func TestStrictJSONReturnsErrorOnInvalidPayload(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
}
Expand All @@ -232,6 +266,8 @@ func TestStrictJSONReturnsErrorOnInvalidPayload(t *testing.T) {
}

func TestLimitedJSONDecodesValidPayload(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
}
Expand All @@ -248,6 +284,8 @@ func TestLimitedJSONDecodesValidPayload(t *testing.T) {
}

func TestLimitedJSONUsesDefaultOnNegativeMaxSize(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
}
Expand All @@ -264,6 +302,8 @@ func TestLimitedJSONUsesDefaultOnNegativeMaxSize(t *testing.T) {
}

func TestLimitedJSONReturnsErrorOnInvalidPayload(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
}
Expand All @@ -279,6 +319,8 @@ func TestLimitedJSONReturnsErrorOnInvalidPayload(t *testing.T) {
}

func TestStrictLimitedJSONDecodesValidPayload(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
}
Expand All @@ -295,6 +337,8 @@ func TestStrictLimitedJSONDecodesValidPayload(t *testing.T) {
}

func TestStrictLimitedJSONRejectsUnknownFields(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
}
Expand All @@ -310,6 +354,8 @@ func TestStrictLimitedJSONRejectsUnknownFields(t *testing.T) {
}

func TestStrictLimitedJSONUsesDefaultOnNegativeMaxSize(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
}
Expand All @@ -326,6 +372,8 @@ func TestStrictLimitedJSONUsesDefaultOnNegativeMaxSize(t *testing.T) {
}

func TestStrictLimitedJSONReturnsErrorOnInvalidPayload(t *testing.T) {
t.Parallel()

type payload struct {
Name string `json:"name"`
}
Expand All @@ -341,6 +389,8 @@ func TestStrictLimitedJSONReturnsErrorOnInvalidPayload(t *testing.T) {
}

func TestXMLDecodesValidPayload(t *testing.T) {
t.Parallel()

type payload struct {
Name string `xml:"name"`
}
Expand All @@ -357,6 +407,8 @@ func TestXMLDecodesValidPayload(t *testing.T) {
}

func TestXMLReturnsErrorOnInvalidPayload(t *testing.T) {
t.Parallel()

type payload struct {
Name string `xml:"name"`
}
Expand All @@ -372,6 +424,8 @@ func TestXMLReturnsErrorOnInvalidPayload(t *testing.T) {
}

func TestLimitedXMLDecodesValidPayload(t *testing.T) {
t.Parallel()

type payload struct {
Name string `xml:"name"`
}
Expand All @@ -388,6 +442,8 @@ func TestLimitedXMLDecodesValidPayload(t *testing.T) {
}

func TestLimitedXMLUsesDefaultOnNegativeMaxSize(t *testing.T) {
t.Parallel()

type payload struct {
Name string `xml:"name"`
}
Expand All @@ -404,6 +460,8 @@ func TestLimitedXMLUsesDefaultOnNegativeMaxSize(t *testing.T) {
}

func TestLimitedXMLReturnsErrorOnInvalidPayload(t *testing.T) {
t.Parallel()

type payload struct {
Name string `xml:"name"`
}
Expand Down
Loading
Loading