-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnut_test.go
39 lines (30 loc) · 905 Bytes
/
nut_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 sqrl_test
import (
"testing"
"github.com/stretchr/testify/assert"
sqrl "github.com/RaniSputnik/sqrl-go"
)
func TestNut(t *testing.T) {
nutter := sqrl.NewNutter()
t.Run("ReturnsANonEmptyValue", func(t *testing.T) {
result := nutter.Next()
assert.NotEmpty(t, result)
})
t.Run("ReturnsBase64EncodedString", func(t *testing.T) {
result := nutter.Next()
_, err := sqrl.Base64.DecodeString(string(result))
assert.NoError(t, err, "Expected nut to be base64 encoded, but got an error during decoding")
})
t.Run("DoesNotRepeatNuts", func(t *testing.T) {
results := map[sqrl.Nut]struct{}{}
for i := 0; i < 1000; i++ {
result := nutter.Next()
if !assert.NotContainsf(t, results, result, "Found duplicate nut: '%s'", result) {
break
}
results[result] = struct{}{}
t.Logf("Got nut: %s", result)
}
})
// TODO: Check allows concurrent generation of nuts?
}