@@ -2,13 +2,58 @@ package idpsync_test
2
2
3
3
import (
4
4
"encoding/json"
5
+ "regexp"
5
6
"testing"
6
7
7
8
"github.com/stretchr/testify/require"
8
9
9
10
"github.com/coder/coder/v2/coderd/idpsync"
10
11
)
11
12
13
+ // TestMarshalJSONEmpty ensures no empty maps are marshaled as `null` in JSON.
14
+ func TestMarshalJSONEmpty (t * testing.T ) {
15
+ t .Parallel ()
16
+
17
+ t .Run ("Group" , func (t * testing.T ) {
18
+ t .Parallel ()
19
+
20
+ output , err := json .Marshal (& idpsync.GroupSyncSettings {
21
+ RegexFilter : regexp .MustCompile (".*" ),
22
+ })
23
+ require .NoError (t , err , "marshal empty group settings" )
24
+ require .NotContains (t , string (output ), "null" )
25
+
26
+ require .JSONEq (t ,
27
+ `{"field":"","mapping":{},"regex_filter":".*","auto_create_missing_groups":false}` ,
28
+ string (output ))
29
+ })
30
+
31
+ t .Run ("Role" , func (t * testing.T ) {
32
+ t .Parallel ()
33
+
34
+ output , err := json .Marshal (& idpsync.RoleSyncSettings {})
35
+ require .NoError (t , err , "marshal empty group settings" )
36
+ require .NotContains (t , string (output ), "null" )
37
+
38
+ require .JSONEq (t ,
39
+ `{"field":"","mapping":{}}` ,
40
+ string (output ))
41
+ })
42
+
43
+ t .Run ("Organization" , func (t * testing.T ) {
44
+ t .Parallel ()
45
+
46
+ output , err := json .Marshal (& idpsync.OrganizationSyncSettings {})
47
+ require .NoError (t , err , "marshal empty group settings" )
48
+ require .NotContains (t , string (output ), "null" )
49
+
50
+ require .JSONEq (t ,
51
+ `{"field":"","mapping":{},"assign_default":false}` ,
52
+ string (output ))
53
+ })
54
+
55
+ }
56
+
12
57
func TestParseStringSliceClaim (t * testing.T ) {
13
58
t .Parallel ()
14
59
0 commit comments