Skip to content

Commit f5c86b9

Browse files
committed
fix: improve trap logging
1 parent fa3ebdb commit f5c86b9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mock.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,10 @@ type Trap struct {
738738
unreleasedCalls int
739739
}
740740

741+
func (t *Trap) String() string {
742+
return fmt.Sprintf("%s(..., %v)", t.fn.String(), t.tags)
743+
}
744+
741745
func (t *Trap) catch(c *apiCall) {
742746
select {
743747
case t.calls <- c:
@@ -763,12 +767,13 @@ func (t *Trap) Close() {
763767
defer t.mock.mu.Unlock()
764768
select {
765769
case <-t.done:
770+
t.mock.tb.Logf("trap %s already Closed()", t)
766771
return // already closed
767772
default:
768773
}
769774
if t.unreleasedCalls != 0 {
770775
t.mock.tb.Helper()
771-
t.mock.tb.Errorf("trap Closed() with %d unreleased calls", t.unreleasedCalls)
776+
t.mock.tb.Errorf("trap %s Closed() with %d unreleased calls", t, t.unreleasedCalls)
772777
}
773778
for i, tr := range t.mock.traps {
774779
if t == tr {
@@ -814,7 +819,7 @@ func (t *Trap) MustWait(ctx context.Context) *Call {
814819
t.mock.tb.Helper()
815820
c, err := t.Wait(ctx)
816821
if err != nil {
817-
t.mock.tb.Fatalf("context expired while waiting for trap: %s", err.Error())
822+
t.mock.tb.Fatalf("context expired while waiting for trap %s: %s", t, err.Error())
818823
}
819824
return c
820825
}

0 commit comments

Comments
 (0)