MCPcopy Index your code
hub / github.com/coder/coder / TestMarshalJSONEmpty

Function TestMarshalJSONEmpty

coderd/idpsync/idpsync_test.go:14–54  ·  view source on GitHub ↗

TestMarshalJSONEmpty ensures no empty maps are marshaled as `null` in JSON.

(t *testing.T)

Source from the content-addressed store, hash-verified

12
13// TestMarshalJSONEmpty ensures no empty maps are marshaled as `null` in JSON.
14func 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
56func TestParseStringSliceClaim(t *testing.T) {
57 t.Parallel()

Callers

nothing calls this directly

Calls 3

MustCompileMethod · 0.80
RunMethod · 0.65
MarshalMethod · 0.45

Tested by

no test coverage detected