-
Notifications
You must be signed in to change notification settings - Fork 1
/
app_test.go
70 lines (56 loc) · 1.73 KB
/
app_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package passage_test
import (
"sync"
"testing"
"github.com/passageidentity/passage-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCreateMagicLink(t *testing.T) {
psg, err := passage.New(PassageAppID, &passage.Config{
APIKey: PassageApiKey, // An API_KEY environment variable is required for testing.
})
require.Nil(t, err)
createMagicLinkBody := passage.CreateMagicLinkBody{
Email: "chris@passage.id",
Channel: passage.EmailChannel,
TTL: 12,
Type: passage.LoginType,
}
magicLink, err := psg.CreateMagicLink(createMagicLinkBody)
require.Nil(t, err)
assert.Equal(t, createMagicLinkBody.Email, magicLink.Identifier)
assert.Equal(t, createMagicLinkBody.TTL, magicLink.TTL)
}
func TestGetApp(t *testing.T) {
psg, err := passage.New(PassageAppID, &passage.Config{
APIKey: PassageApiKey, // An API_KEY environment variable is required for testing.
})
require.Nil(t, err)
appInfo, err := psg.GetApp()
assert.Nil(t, err)
assert.Equal(t, PassageAppID, appInfo.ID)
}
func TestAppNewJWKSCache(t *testing.T) {
psg, err := passage.New(PassageAppID, &passage.Config{
APIKey: PassageApiKey, // An API_KEY environment variable is required for testing.
})
require.Nil(t, err)
assert.NotNil(t, psg.JWKS)
}
// should be run with the -race flag, i.e. `go test -race -run TestAppJWKSCacheWriteConcurrency`
func TestAppJWKSCacheWriteConcurrency(t *testing.T) {
goRoutineCount := 2
var wg sync.WaitGroup
wg.Add(goRoutineCount)
for i := 0; i < goRoutineCount; i++ {
go func() {
defer wg.Done()
_, err := passage.New(PassageAppID, &passage.Config{
APIKey: PassageApiKey, // An API_KEY environment variable is required for testing.
})
require.Nil(t, err)
}()
}
wg.Wait()
}