Skip to content

Commit 31138a2

Browse files
authored
Simplify mock service Close (#30)
1 parent e3f97c4 commit 31138a2

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

mock/service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,14 @@ func containsAll(have, want []uint32) bool {
9999
}
100100
return true
101101
}
102+
103+
// Close resets the buffer and releases any held resources.
104+
func (s *Service) Close() error {
105+
s.mu.Lock()
106+
defer s.mu.Unlock()
107+
s.buf = nil
108+
s.next = 0
109+
s.size = 0
110+
s.capacity = 0
111+
return nil
112+
}

mock/service_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ func TestServiceQueryIntersection(t *testing.T) {
4747
}
4848
assert.Equal(t, []string{"b"}, res)
4949
}
50+
51+
func TestServiceCloseResets(t *testing.T) {
52+
svc := NewService(2)
53+
svc.Log("pending", 1)
54+
55+
err := svc.Close()
56+
assert.NoError(t, err)
57+
assert.Equal(t, 0, svc.capacity)
58+
assert.Nil(t, svc.buf)
59+
assert.Zero(t, svc.size)
60+
assert.Zero(t, svc.next)
61+
}

0 commit comments

Comments
 (0)