@@ -11,6 +11,7 @@ import (
11
11
12
12
"github.com/coder/coder/v2/cli/clitest"
13
13
"github.com/coder/coder/v2/coderd/coderdtest"
14
+ "github.com/coder/coder/v2/coderd/rbac"
14
15
"github.com/coder/coder/v2/codersdk"
15
16
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
16
17
"github.com/coder/coder/v2/enterprise/coderd/license"
@@ -69,3 +70,53 @@ func TestUpdateGroupSync(t *testing.T) {
69
70
require .JSONEq (t , string (expectedData ), buf .String ())
70
71
})
71
72
}
73
+
74
+ func TestUpdateRoleSync (t * testing.T ) {
75
+ t .Parallel ()
76
+
77
+ t .Run ("OK" , func (t * testing.T ) {
78
+ dv := coderdtest .DeploymentValues (t )
79
+ dv .Experiments = []string {string (codersdk .ExperimentMultiOrganization )}
80
+
81
+ owner , _ := coderdenttest .New (t , & coderdenttest.Options {
82
+ Options : & coderdtest.Options {
83
+ DeploymentValues : dv ,
84
+ },
85
+ LicenseOptions : & coderdenttest.LicenseOptions {
86
+ Features : license.Features {
87
+ codersdk .FeatureMultipleOrganizations : 1 ,
88
+ },
89
+ },
90
+ })
91
+
92
+ ctx := testutil .Context (t , testutil .WaitLong )
93
+ inv , root := clitest .New (t , "organization" , "settings" , "set" , "rolesync" )
94
+ clitest .SetupConfig (t , owner , root )
95
+
96
+ expectedSettings := codersdk.RoleSyncSettings {
97
+ Field : "roles" ,
98
+ Mapping : map [string ][]string {
99
+ "test" : {rbac .RoleOrgAdmin ()},
100
+ },
101
+ }
102
+ expectedData , err := json .Marshal (expectedSettings )
103
+ require .NoError (t , err )
104
+
105
+ buf := new (bytes.Buffer )
106
+ inv .Stdout = buf
107
+ inv .Stdin = bytes .NewBuffer (expectedData )
108
+ err = inv .WithContext (ctx ).Run ()
109
+ require .NoError (t , err )
110
+ require .JSONEq (t , string (expectedData ), buf .String ())
111
+
112
+ // Now read it back
113
+ inv , root = clitest .New (t , "organization" , "settings" , "show" , "rolesync" )
114
+ clitest .SetupConfig (t , owner , root )
115
+
116
+ buf = new (bytes.Buffer )
117
+ inv .Stdout = buf
118
+ err = inv .WithContext (ctx ).Run ()
119
+ require .NoError (t , err )
120
+ require .JSONEq (t , string (expectedData ), buf .String ())
121
+ })
122
+ }
0 commit comments