-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathscim_test.go
71 lines (63 loc) · 1.76 KB
/
scim_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
71
package urn
import (
"encoding/json"
"fmt"
"testing"
scimschema "github.com/leodido/go-urn/scim/schema"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSCIMJSONMarshaling(t *testing.T) {
t.Run("roundtrip", func(t *testing.T) {
// Marshal
exp := SCIM{Type: scimschema.Schemas, Name: "core", Other: "extension:enterprise:2.0:User"}
mar, err := json.Marshal(exp)
require.NoError(t, err)
require.Equal(t, `"urn:ietf:params:scim:schemas:core:extension:enterprise:2.0:User"`, string(mar))
// Unmarshal
var act SCIM
err = json.Unmarshal(mar, &act)
require.NoError(t, err)
exp.pos = 34
require.Equal(t, exp, act)
})
t.Run("unmarshal", func(t *testing.T) {
exp := `urn:ietf:params:scim:schemas:extension:enterprise:2.0:User`
var got SCIM
err := json.Unmarshal([]byte(fmt.Sprintf(`"%s"`, exp)), &got)
if !assert.NoError(t, err) {
return
}
assert.Equal(t, exp, got.String())
assert.Equal(t, SCIM{
Type: scimschema.Schemas,
Name: "extension",
Other: "enterprise:2.0:User",
pos: 39,
}, got)
})
t.Run("unmarshal without the <other> part", func(t *testing.T) {
exp := `urn:ietf:params:scim:schemas:core`
var got SCIM
err := json.Unmarshal([]byte(fmt.Sprintf(`"%s"`, exp)), &got)
if !assert.NoError(t, err) {
return
}
assert.Equal(t, exp, got.String())
assert.Equal(t, SCIM{
Type: scimschema.Schemas,
Name: "core",
pos: 29,
}, got)
})
t.Run("invalid URN", func(t *testing.T) {
var actual SCIM
err := json.Unmarshal([]byte(`"not a URN"`), &actual)
assert.EqualError(t, err, "invalid SCIM URN: not a URN")
})
t.Run("empty", func(t *testing.T) {
var actual SCIM
err := actual.UnmarshalJSON(nil)
assert.EqualError(t, err, "unexpected end of JSON input")
})
}