Skip to content

Commit 11bc79a

Browse files
test: add context_test.go
1 parent 2edfb25 commit 11bc79a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pkg/smartrequeue/context_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package smartrequeue
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestNewContext(t *testing.T) {
11+
entry := &Entry{}
12+
ctx := NewContext(context.Background(), entry)
13+
14+
if got := FromContext(ctx); got != entry {
15+
assert.Equal(t, entry, got, "Expected entry to be the same as the one set in context")
16+
}
17+
}
18+
19+
func TestFromContext(t *testing.T) {
20+
entry := &Entry{}
21+
ctx := NewContext(context.Background(), entry)
22+
23+
if got := FromContext(ctx); got != entry {
24+
25+
assert.Equal(t, entry, got, "Expected entry to be the same as the one set in context")
26+
}
27+
28+
if got := FromContext(context.Background()); got != nil {
29+
assert.Nil(t, got, "Expected nil when no entry is set in context")
30+
}
31+
}

0 commit comments

Comments
 (0)