@@ -2,9 +2,11 @@ package urn
2
2
3
3
import (
4
4
"encoding/json"
5
+ "fmt"
5
6
"testing"
6
7
7
8
scimschema "github.com/leodido/go-urn/scim/schema"
9
+ "github.com/stretchr/testify/assert"
8
10
"github.com/stretchr/testify/require"
9
11
)
10
12
@@ -14,12 +16,56 @@ func TestSCIMJSONMarshaling(t *testing.T) {
14
16
exp := SCIM {Type : scimschema .Schemas , Name : "core" , Other : "extension:enterprise:2.0:User" }
15
17
mar , err := json .Marshal (exp )
16
18
require .NoError (t , err )
19
+ require .Equal (t , `"urn:ietf:params:scim:schemas:core:extension:enterprise:2.0:User"` , string (mar ))
17
20
18
21
// Unmarshal
19
22
var act SCIM
20
23
err = json .Unmarshal (mar , & act )
21
24
require .NoError (t , err )
22
-
25
+ exp . pos = 34
23
26
require .Equal (t , exp , act )
24
27
})
28
+
29
+ t .Run ("unmarshal" , func (t * testing.T ) {
30
+ exp := `urn:ietf:params:scim:schemas:extension:enterprise:2.0:User`
31
+ var got SCIM
32
+ err := json .Unmarshal ([]byte (fmt .Sprintf (`"%s"` , exp )), & got )
33
+ if ! assert .NoError (t , err ) {
34
+ return
35
+ }
36
+ assert .Equal (t , exp , got .String ())
37
+ assert .Equal (t , SCIM {
38
+ Type : scimschema .Schemas ,
39
+ Name : "extension" ,
40
+ Other : "enterprise:2.0:User" ,
41
+ pos : 39 ,
42
+ }, got )
43
+ })
44
+
45
+ t .Run ("unmarshal without the <other> part" , func (t * testing.T ) {
46
+ exp := `urn:ietf:params:scim:schemas:core`
47
+ var got SCIM
48
+ err := json .Unmarshal ([]byte (fmt .Sprintf (`"%s"` , exp )), & got )
49
+ if ! assert .NoError (t , err ) {
50
+ return
51
+ }
52
+ assert .Equal (t , exp , got .String ())
53
+ assert .Equal (t , SCIM {
54
+ Type : scimschema .Schemas ,
55
+ Name : "core" ,
56
+ pos : 29 ,
57
+ }, got )
58
+ })
59
+
60
+ t .Run ("invalid URN" , func (t * testing.T ) {
61
+ var actual SCIM
62
+ err := json .Unmarshal ([]byte (`"not a URN"` ), & actual )
63
+ assert .EqualError (t , err , "invalid SCIM URN: not a URN" )
64
+ })
65
+
66
+ t .Run ("empty" , func (t * testing.T ) {
67
+ var actual SCIM
68
+ err := actual .UnmarshalJSON (nil )
69
+ assert .EqualError (t , err , "unexpected end of JSON input" )
70
+ })
25
71
}
0 commit comments