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
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
arch: arm64
- os: windows-latest
arch: amd64
- os: macos-15-intel
- os: macos-26-intel
arch: amd64
- os: macos-15
- os: macos-26
arch: arm64
steps:
- uses: actions/checkout@v6
Expand Down
10 changes: 5 additions & 5 deletions examples/panic/panic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ func TestSimulatePanicInDependency(t *testing.T) {

// Override riskyOperation to panic
Override(ctx, riskyOperation, Once, func(data []string, index int) string {
Expectation().CheckArgs([]string{"a", "b"}, 5)
Expectation().CheckArgs(data, index)
panic("index out of bounds")
})([]string{"a", "b"}, 5)

// Override handlePanic to verify it's called with the right panic value
Override(ctx, handlePanic, Once, func(r interface{}) error {
Expectation().CheckArgs("index out of bounds")
Expectation().CheckArgs(r)
return ErrCritical
})("index out of bounds")

Expand Down Expand Up @@ -76,7 +76,7 @@ func TestRecoveryLogic(t *testing.T) {
func TestValidationPanic(t *testing.T) {
// Override validateInput to not panic, return error instead
Override(TestingContext(t), validateInput, Once, func(value int) error {
Expectation().CheckArgs(-5)
Expectation().CheckArgs(value)
// Instead of panicking, return an error
return errors.New("negative values not allowed")
})(-5)
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestQueryPanicPrevention(t *testing.T) {
// Override Query to avoid panic
Override(TestingContext(t), (*Database).Query, Once,
func(db *Database, sql string) ([]string, error) {
Expectation().CheckArgs(db, "")
Expectation().CheckArgs(db, sql)
// Return error gracefully instead of panicking
return nil, fmt.Errorf("empty SQL not allowed")
})(db, "")
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestSafeQueryWithPanicRecovery(t *testing.T) {
func TestDivisionByZero(t *testing.T) {
// Override DivideNumbers to not panic
Override(TestingContext(t), DivideNumbers, Once, func(a, b float64) float64 {
Expectation().CheckArgs(10.0, 0.0)
Expectation().CheckArgs(a, b)
// Handle gracefully - return zero or infinity
return 0.0
})(10.0, 0.0)
Expand Down
24 changes: 12 additions & 12 deletions examples/variadic/variadic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestVariadicNoArgs(t *testing.T) {
Override(TestingContext(t), formatList, Once, func(sep string, items ...string) string {
// When checking args with variadic parameters, pass the variadic part as a slice
Expectation().CheckArgs(sep, []string{})
Expectation().CheckArgs(sep, items)
return "mocked-empty"
})(", ") // Call with just the separator, no variadic args

Expand All @@ -27,7 +27,7 @@ func TestVariadicNoArgs(t *testing.T) {
// TestVariadicSingleArg tests overriding with a single variadic argument
func TestVariadicSingleArg(t *testing.T) {
Override(TestingContext(t), formatList, Once, func(sep string, items ...string) string {
Expectation().CheckArgs(sep, []string{"one"})
Expectation().CheckArgs(sep, items)
return "mocked-single"
})(", ", "one") // Call with separator and one item

Expand All @@ -42,7 +42,7 @@ func TestVariadicSingleArg(t *testing.T) {
// TestVariadicMultipleArgs tests overriding with multiple variadic arguments
func TestVariadicMultipleArgs(t *testing.T) {
Override(TestingContext(t), formatList, Once, func(sep string, items ...string) string {
Expectation().CheckArgs(sep, []string{"alpha", "beta", "gamma"})
Expectation().CheckArgs(sep, items)
return "mocked-multiple"
})(" | ", "alpha", "beta", "gamma") // Call with separator and multiple items

Expand All @@ -61,7 +61,7 @@ func TestVariadicMethod(t *testing.T) {
// For methods, receiver is first arg, then regular args, then variadic args individually
Override(TestingContext(t), (*Logger).Log, Once,
func(l *Logger, format string, args ...interface{}) string {
Expectation().CheckArgs(l, format, []interface{}{"REQ-123", 3})
Expectation().CheckArgs(l, format, args)
return "[TEST] mocked log"
})(logger, "Processing request %s with %d parameters", "REQ-123", 3)

Expand All @@ -76,7 +76,7 @@ func TestVariadicMethod(t *testing.T) {
// TestStdlibVariadic tests overriding standard library variadic function
func TestStdlibVariadic(t *testing.T) {
Override(TestingContext(t), fmt.Sprintf, Once, func(format string, args ...interface{}) string {
Expectation().CheckArgs(format, []interface{}{"test", 42})
Expectation().CheckArgs(format, args)
return "mocked sprintf"
})("Format: %s = %d", "test", 42)

Expand All @@ -101,7 +101,7 @@ func TestProcessRequestSuccess(t *testing.T) {

// Mock formatList to verify it's called correctly
Override(ctx, formatList, Once, func(sep string, items ...string) string {
Expectation().CheckArgs(sep, []string{"param1", "param2", "param3"})
Expectation().CheckArgs(sep, items)
return "param1, param2, param3"
})(", ", "param1", "param2", "param3")

Expand All @@ -122,7 +122,7 @@ func TestVariadicErrorContext(t *testing.T) {

// Test with no context
Override(TestingContext(t), logError, Once, func(err error, context ...string) string {
Expectation().CheckArgs(err, []string{})
Expectation().CheckArgs(err, context)
return "mocked: no context"
})(err) // No context args

Expand All @@ -133,7 +133,7 @@ func TestVariadicErrorContext(t *testing.T) {

// Test with single context item
Override(TestingContext(t), logError, Once, func(err error, context ...string) string {
Expectation().CheckArgs(err, []string{"database"})
Expectation().CheckArgs(err, context)
return "mocked: single context"
})(err, "database") // One context arg

Expand All @@ -144,7 +144,7 @@ func TestVariadicErrorContext(t *testing.T) {

// Test with multiple context items
Override(TestingContext(t), logError, Once, func(err error, context ...string) string {
Expectation().CheckArgs(err, []string{"database", "user-service", "retry-3"})
Expectation().CheckArgs(err, context)
return "mocked: multiple context"
})(err, "database", "user-service", "retry-3") // Multiple context args

Expand All @@ -162,19 +162,19 @@ func TestVariadicChain(t *testing.T) {

// First call - no items
Override(ctx, formatList, Once, func(sep string, items ...string) string {
Expectation().CheckArgs(sep, []string{})
Expectation().CheckArgs(sep, items)
return "first"
})(", ")

// Second call - one item
Override(ctx, formatList, Once, func(sep string, items ...string) string {
Expectation().CheckArgs(sep, []string{"item1"})
Expectation().CheckArgs(sep, items)
return "second"
})(", ", "item1")

// Third call - multiple items
Override(ctx, formatList, Once, func(sep string, items ...string) string {
Expectation().CheckArgs(sep, []string{"a", "b", "c"})
Expectation().CheckArgs(sep, items)
return "third"
})(", ", "a", "b", "c")

Expand Down