Skip to content

Commit

Permalink
Add validation scopes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Sep 26, 2024
1 parent f1528e8 commit 8aa7bdf
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ The format is based on [Keep a Changelog], and this project adheres to
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
[semantic versioning]: https://semver.org/spec/v2.0.0.html

## [Unreleased]

### Added

- Added `CommandValidationScope()`, `EventValidationScope()`, and
`TimeoutValidationScope()` to help when testing message validation logic.

## [0.17.2] - 2024-09-25

### Fixed
Expand Down
42 changes: 42 additions & 0 deletions validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package testkit

import (
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/testkit/internal/validation"
)

// CommandValidationScope returns a [dogma.CommandValidationScope] that can be
// used when testing command validation logic.
func CommandValidationScope(...CommandValidationScopeOption) dogma.CommandValidationScope {
return validation.CommandValidationScope()
}

// EventValidationScope returns a [dogma.EventValidationScope] that can be used
// when testing event validation logic.
func EventValidationScope(...EventValidationScopeOption) dogma.EventValidationScope {
return validation.EventValidationScope()
}

// TimeoutValidationScope returns a [dogma.TimeoutValidationScope] that can be
// used when testing timeout validation logic.
func TimeoutValidationScope(...TimeoutValidationScopeOption) dogma.TimeoutValidationScope {
return validation.TimeoutValidationScope()
}

// CommandValidationScopeOption is an option that changes the behavior of a
// [dogma.CommandValidationScope] created by calling [CommandValidationScope].
type CommandValidationScopeOption interface {
reservedCommandValidationScopeOption()
}

// EventValidationScopeOption is an option that changes the behavior of a
// [dogma.EventValidationScope] created by calling [EventValidationScope].
type EventValidationScopeOption interface {
reservedEventValidationScopeOption()
}

// TimeoutValidationScopeOption is an option that changes the behavior of a
// [dogma.TimeoutValidationScope] created by calling [TimeoutValidationScope].
type TimeoutValidationScopeOption interface {
reservedTimeoutValidationScopeOption()
}
21 changes: 21 additions & 0 deletions validation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package testkit_test

import (
"testing"

. "github.com/dogmatiq/testkit"
)

func TestValidationScopeCreation(t *testing.T) {
if CommandValidationScope() == nil {
t.Errorf("CommandValidationScope() returned nil")
}

if EventValidationScope() == nil {
t.Errorf("EventValidationScope() returned nil")
}

if TimeoutValidationScope() == nil {
t.Errorf("TimeoutValidationScope() returned nil")
}
}

0 comments on commit 8aa7bdf

Please sign in to comment.