-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels_test.go
More file actions
36 lines (33 loc) · 939 Bytes
/
models_test.go
File metadata and controls
36 lines (33 loc) · 939 Bytes
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
package plexus
import (
"encoding/base64"
"encoding/json"
"errors"
"testing"
"github.com/Kairum-Labs/should"
)
func TestDecodeToken(t *testing.T) {
t.Run("badEncoding", func(t *testing.T) {
value, err := DecodeToken("bad")
var expectedErr base64.CorruptInputError
should.BeEqual(t, true, errors.As(err, &expectedErr))
should.BeEqual(t, value, KeyValue{})
})
t.Run("bad", func(t *testing.T) {
value, err := DecodeToken(base64.StdEncoding.EncodeToString([]byte("bad")))
should.ContainSubstring(t, err.Error(), "invalid character")
should.BeEqual(t, value, KeyValue{})
})
t.Run("good", func(t *testing.T) {
value := KeyValue{
URL: "example.com",
Seed: "seed",
KeyName: "testing",
}
payload, err := json.Marshal(&value)
should.NotBeError(t, err)
keyValue, err := DecodeToken(base64.StdEncoding.EncodeToString(payload))
should.NotBeError(t, err)
should.BeEqual(t, keyValue, value)
})
}