Initial commit: Custom Start Page application with authentication and DynamoDB storage
This commit is contained in:
43
internal/testing/helpers.go
Normal file
43
internal/testing/helpers.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package testing
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/leanovate/gopter"
|
||||
)
|
||||
|
||||
// PropertyTestConfig holds configuration for property-based tests
|
||||
type PropertyTestConfig struct {
|
||||
MinSuccessfulTests int
|
||||
MaxSize int
|
||||
Workers int
|
||||
}
|
||||
|
||||
// DefaultPropertyTestConfig returns default configuration for property tests
|
||||
func DefaultPropertyTestConfig() *PropertyTestConfig {
|
||||
return &PropertyTestConfig{
|
||||
MinSuccessfulTests: 100,
|
||||
MaxSize: 100,
|
||||
Workers: 4,
|
||||
}
|
||||
}
|
||||
|
||||
// RunPropertyTest runs a property-based test with the given configuration
|
||||
func RunPropertyTest(t *testing.T, config *PropertyTestConfig, testFunc func(*gopter.Properties)) {
|
||||
if config == nil {
|
||||
config = DefaultPropertyTestConfig()
|
||||
}
|
||||
|
||||
parameters := gopter.DefaultTestParameters()
|
||||
parameters.MinSuccessfulTests = config.MinSuccessfulTests
|
||||
parameters.MaxSize = config.MaxSize
|
||||
parameters.Workers = config.Workers
|
||||
|
||||
properties := gopter.NewProperties(parameters)
|
||||
|
||||
// Call the test function to add properties
|
||||
testFunc(properties)
|
||||
|
||||
// Run the tests
|
||||
properties.TestingRun(t)
|
||||
}
|
||||
55
internal/testing/helpers_test.go
Normal file
55
internal/testing/helpers_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package testing
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/leanovate/gopter"
|
||||
"github.com/leanovate/gopter/gen"
|
||||
"github.com/leanovate/gopter/prop"
|
||||
)
|
||||
|
||||
func TestDefaultPropertyTestConfig(t *testing.T) {
|
||||
cfg := DefaultPropertyTestConfig()
|
||||
|
||||
if cfg.MinSuccessfulTests != 100 {
|
||||
t.Errorf("Expected MinSuccessfulTests to be 100, got %d", cfg.MinSuccessfulTests)
|
||||
}
|
||||
|
||||
if cfg.MaxSize != 100 {
|
||||
t.Errorf("Expected MaxSize to be 100, got %d", cfg.MaxSize)
|
||||
}
|
||||
|
||||
if cfg.Workers != 4 {
|
||||
t.Errorf("Expected Workers to be 4, got %d", cfg.Workers)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunPropertyTest(t *testing.T) {
|
||||
// Simple property: for all integers, x + 0 = x
|
||||
RunPropertyTest(t, nil, func(properties *gopter.Properties) {
|
||||
properties.Property("addition identity", prop.ForAll(
|
||||
func(x int) bool {
|
||||
return x+0 == x
|
||||
},
|
||||
gen.Int(),
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunPropertyTestWithCustomConfig(t *testing.T) {
|
||||
cfg := &PropertyTestConfig{
|
||||
MinSuccessfulTests: 50,
|
||||
MaxSize: 50,
|
||||
Workers: 2,
|
||||
}
|
||||
|
||||
// Simple property: for all strings, len(s) >= 0
|
||||
RunPropertyTest(t, cfg, func(properties *gopter.Properties) {
|
||||
properties.Property("string length non-negative", prop.ForAll(
|
||||
func(s string) bool {
|
||||
return len(s) >= 0
|
||||
},
|
||||
gen.AnyString(),
|
||||
))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user