context_test.go
 1package access
 2
 3import (
 4	"context"
 5	"testing"
 6)
 7
 8func TestGoodFromContext(t *testing.T) {
 9	ctx := WithContext(context.TODO(), AdminAccess)
10	if ac := FromContext(ctx); ac != AdminAccess {
11		t.Errorf("FromContext(ctx) => %d, want %d", ac, AdminAccess)
12	}
13}
14
15func TestBadFromContext(t *testing.T) {
16	ctx := context.TODO()
17	if ac := FromContext(ctx); ac != -1 {
18		t.Errorf("FromContext(ctx) => %d, want %d", ac, -1)
19	}
20}