Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): run tests for all modules in repo #11

Merged
merged 2 commits into from
Dec 29, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- run: go test -race -v ./...
- run: go list -m | xargs go test -race -v
28 changes: 14 additions & 14 deletions extensions/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,20 @@ func TestWithPrometheusMetrics(t *testing.T) {

durationsOut1 := `# HELP hoglet_circuit_call_durations_seconds Call durations in seconds
# TYPE hoglet_circuit_call_durations_seconds histogram
hoglet_circuit_call_durations_seconds_bucket{circuit="test",error="true",le="0.005"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",error="true",le="0.01"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",error="true",le="0.025"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",error="true",le="0.05"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",error="true",le="0.1"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",error="true",le="0.25"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",error="true",le="0.5"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",error="true",le="1"} 1
hoglet_circuit_call_durations_seconds_bucket{circuit="test",error="true",le="2.5"} 1
hoglet_circuit_call_durations_seconds_bucket{circuit="test",error="true",le="5"} 1
hoglet_circuit_call_durations_seconds_bucket{circuit="test",error="true",le="10"} 1
hoglet_circuit_call_durations_seconds_bucket{circuit="test",error="true",le="+Inf"} 1
hoglet_circuit_call_durations_seconds_sum{circuit="test",error="true"} 1
hoglet_circuit_call_durations_seconds_count{circuit="test",error="true"} 1
hoglet_circuit_call_durations_seconds_bucket{circuit="test",success="false",le="0.005"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",success="false",le="0.01"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",success="false",le="0.025"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",success="false",le="0.05"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",success="false",le="0.1"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",success="false",le="0.25"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",success="false",le="0.5"} 0
hoglet_circuit_call_durations_seconds_bucket{circuit="test",success="false",le="1"} 1
hoglet_circuit_call_durations_seconds_bucket{circuit="test",success="false",le="2.5"} 1
hoglet_circuit_call_durations_seconds_bucket{circuit="test",success="false",le="5"} 1
hoglet_circuit_call_durations_seconds_bucket{circuit="test",success="false",le="10"} 1
hoglet_circuit_call_durations_seconds_bucket{circuit="test",success="false",le="+Inf"} 1
hoglet_circuit_call_durations_seconds_sum{circuit="test",success="false"} 1
hoglet_circuit_call_durations_seconds_count{circuit="test",success="false"} 1
# HELP hoglet_circuit_dropped_calls_total Total number of calls with an open circuit (i.e.: calls that did not reach the wrapped function)
# TYPE hoglet_circuit_dropped_calls_total counter
hoglet_circuit_dropped_calls_total{cause="circuit_open",circuit="test"} 1
Expand Down
19 changes: 12 additions & 7 deletions hoglet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,22 @@ func TestHoglet_Do(t *testing.T) {
}

var err error
maybeAssertPanic := assert.NotPanics
if call.wantPanic != nil {
maybeAssertPanic = func(t assert.TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) bool {
return assert.PanicsWithValue(t, call.wantPanic, f, msgAndArgs...)
}
}
maybeAssertPanic(t, func() {
_, err = h.Call(context.Background(), call.arg)
})
}, call.wantPanic)
assert.Equal(t, call.wantErr, err, "unexpected error on call %d: %v", i, err)
}
})
}
}

// maybeAssertPanic is a test-table helper to assert that a function panics or not, depending on the value of wantPanic.
func maybeAssertPanic(t *testing.T, f func(), wantPanic any) {
wrapped := assert.NotPanics
if wantPanic != nil {
wrapped = func(t assert.TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) bool {
return assert.PanicsWithValue(t, wantPanic, f, msgAndArgs...)
}
}
wrapped(t, f)
}