diff --git a/CHANGELOG.md b/CHANGELOG.md index db19652..2f6581b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/validation.go b/validation.go new file mode 100644 index 0000000..8c1c50f --- /dev/null +++ b/validation.go @@ -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() +} diff --git a/validation_test.go b/validation_test.go new file mode 100644 index 0000000..1590153 --- /dev/null +++ b/validation_test.go @@ -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") + } +}