-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathlist_response_test.go
More file actions
60 lines (51 loc) · 1.44 KB
/
list_response_test.go
File metadata and controls
60 lines (51 loc) · 1.44 KB
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
package scim
import (
"testing"
"time"
"github.com/elimity-com/scim/schema"
)
func TestRawResourcesDoesNotMutateHandlerAttributes(t *testing.T) {
t.Parallel()
t.Run("outer map not mutated", func(t *testing.T) {
t.Parallel()
attrs := ResourceAttributes{"displayName": "Test User"}
original := make(ResourceAttributes, len(attrs))
for k, v := range attrs {
original[k] = v
}
p := Page{Resources: []Resource{{ID: "42", Attributes: attrs}}}
_ = p.rawResources()
for k := range attrs {
if _, ok := original[k]; !ok {
t.Errorf("rawResources() injected %q into handler-owned attributes map", k)
}
}
})
t.Run("nested meta map not mutated", func(t *testing.T) {
t.Parallel()
// Handler provides a meta map (e.g. with resourceType pre-filled).
existingMeta := map[string]interface{}{"resourceType": "User"}
originalMeta := make(map[string]interface{}, len(existingMeta))
for k, v := range existingMeta {
originalMeta[k] = v
}
attrs := ResourceAttributes{
"displayName": "Test User",
schema.CommonAttributeMeta: existingMeta,
}
now := time.Now()
p := Page{
Resources: []Resource{{
ID: "42",
Attributes: attrs,
Meta: Meta{Created: &now, LastModified: &now, Version: "W/\"1\""},
}},
}
_ = p.rawResources()
for k := range existingMeta {
if _, ok := originalMeta[k]; !ok {
t.Errorf("rawResources() injected %q into handler-owned meta map", k)
}
}
})
}