lens @ 52276ba99540d6c61195772ccdd50944e96f4959

 1//go:build unit
 2
 3package ext
 4
 5import (
 6	"testing"
 7
 8	"git.sr.ht/~gabrielgio/img/pkg/testkit"
 9)
10
11func TestReadWriteToken(t *testing.T) {
12	t.Parallel()
13
14	testCases := []struct {
15		name  string
16		key   []byte
17		token *Token
18	}{
19		{
20			name: "Normal write",
21			key:  []byte("AES256Key-32Characters1234567890"),
22			token: &Token{
23				UserID:   3,
24				Username: "username",
25			},
26		},
27	}
28
29	for _, tc := range testCases {
30		t.Run(tc.name, func(t *testing.T) {
31			data, err := WriteToken(tc.token, tc.key)
32			testkit.TestFatalError(t, "WriteToken", err)
33
34			token, err := ReadToken(data, tc.key)
35			testkit.TestFatalError(t, "ReadToken", err)
36
37			testkit.TestValue(t, "ReadWriteToken", token, tc.token)
38		})
39	}
40}