-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_test.go
39 lines (30 loc) · 940 Bytes
/
context_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
package teamvite
import (
"context"
"reflect"
"testing"
)
func TestUserFromContext(t *testing.T) {
// Create a Player
expectedPlayer := Player{Name: "Test Player"}
// Create a context with the Player
ctx := NewContextWithUser(context.Background(), &expectedPlayer)
// Call UserFromContext
player := UserFromContext(ctx)
// Check if the returned *Player is as expected
if !reflect.DeepEqual(player, &expectedPlayer) {
t.Errorf("UserFromContext = %v; want %v", player, expectedPlayer)
}
}
func TestUserFromContextWithNilUser(t *testing.T) {
// Create a Player
var expectedPlayer *Player
// Create a context with the Player
ctx := NewContextWithUser(context.Background(), expectedPlayer)
// Call UserFromContext
player := UserFromContext(ctx)
// Check if the returned *Player is as expected
if !reflect.DeepEqual(player, expectedPlayer) {
t.Errorf("UserFromContext = %v; want %v", player, expectedPlayer)
}
}