-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceipts_test.go
49 lines (43 loc) · 1.56 KB
/
receipts_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package stompy
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestReceipts_Add_Timeout(t *testing.T) {
receipt := NewReceipt(time.Millisecond * 100)
err := awaitingReceipt.Add("testid", receipt)
assert.NoError(t, err, "did not expect an error adding receipt")
received := <-receipt.Received
assert.False(t, received, "expected received to false")
receipt = awaitingReceipt.Get("testid")
assert.Nil(t, receipt, "receipt should be cleaned up")
}
func TestReceipts_Add_Duplicate(t *testing.T) {
receipt := NewReceipt(time.Millisecond * 100)
err := awaitingReceipt.Add("testid", receipt)
assert.NoError(t, err, "did not expect an error adding receipt")
err = awaitingReceipt.Add("testid", receipt)
assert.Error(t, err, "expected an error adding duplicate receipt")
}
func TestReceipts_Add(t *testing.T) {
receipt := NewReceipt(time.Millisecond * 100)
err := awaitingReceipt.Add("test2", receipt)
assert.NoError(t, err, "did not expect an error adding receipt")
go func() {
rec := awaitingReceipt.Get("test2")
rec.receiptReceived <- true
}()
received := <-receipt.Received
assert.True(t, received, "expected received to be true")
receipt = awaitingReceipt.Get("test2")
assert.Nil(t, receipt, "receipt should be cleaned up")
}
func TestReceipts_Remove(t *testing.T) {
receipt := NewReceipt(time.Millisecond * 100)
err := awaitingReceipt.Add("test2", receipt)
assert.NoError(t, err, "did not expect an error adding receipt")
awaitingReceipt.Remove("test2")
rec := awaitingReceipt.Get("test2")
assert.Nil(t, rec, "receipt should be removed")
}