@@ -98,6 +98,105 @@ func TestOrganizationsService_ListRoles(t *testing.T) {
98
98
})
99
99
}
100
100
101
+ func TestOrganizationsService_GetOrgRole (t * testing.T ) {
102
+ client , mux , _ , teardown := setup ()
103
+ defer teardown ()
104
+
105
+ // Test built-in org role
106
+ mux .HandleFunc ("/orgs/o/organization-roles/8132" , func (w http.ResponseWriter , r * http.Request ) {
107
+ testMethod (t , r , "GET" )
108
+ fmt .Fprint (w , `{
109
+ "id": 8132,
110
+ "name": "all_repo_read",
111
+ "description": "Grants read access to all repositories in the organization.",
112
+ "permissions": [],
113
+ "created_at": ` + referenceTimeStr + `,
114
+ "updated_at": ` + referenceTimeStr + `,
115
+ "source": "Predefined",
116
+ "base_role": "read"
117
+ }` )
118
+ })
119
+
120
+ ctx := context .Background ()
121
+
122
+ gotBuiltInRole , _ , err := client .Organizations .GetOrgRole (ctx , "o" , 8132 )
123
+ if err != nil {
124
+ t .Errorf ("Organizations.GetOrgRole returned error: %v" , err )
125
+ }
126
+
127
+ wantBuiltInRole := & CustomOrgRoles {
128
+ ID : Int64 (8132 ),
129
+ Name : String ("all_repo_read" ),
130
+ Description : String ("Grants read access to all repositories in the organization." ),
131
+ Permissions : []string {},
132
+ CreatedAt : & Timestamp {referenceTime },
133
+ UpdatedAt : & Timestamp {referenceTime },
134
+ Source : String ("Predefined" ),
135
+ BaseRole : String ("read" ),
136
+ }
137
+
138
+ if ! cmp .Equal (gotBuiltInRole , wantBuiltInRole ) {
139
+ t .Errorf ("Organizations.GetOrgRole returned %+v, want %+v" , gotBuiltInRole , wantBuiltInRole )
140
+ }
141
+
142
+ // Test custom org role
143
+ mux .HandleFunc ("/orgs/o/organization-roles/123456" , func (w http.ResponseWriter , r * http.Request ) {
144
+ testMethod (t , r , "GET" )
145
+ fmt .Fprint (w , `{
146
+ "id": 123456,
147
+ "name": "test-role",
148
+ "description": "test-role",
149
+ "permissions": [
150
+ "read_organization_custom_org_role",
151
+ "read_organization_custom_repo_role",
152
+ "write_organization_custom_org_role"
153
+ ],
154
+ "created_at": ` + referenceTimeStr + `,
155
+ "updated_at": ` + referenceTimeStr + `,
156
+ "source": "Organization",
157
+ "base_role": null
158
+ }` )
159
+ })
160
+
161
+ gotCustomRole , _ , err := client .Organizations .GetOrgRole (ctx , "o" , 123456 )
162
+ if err != nil {
163
+ t .Errorf ("Organizations.GetOrgRole returned error: %v" , err )
164
+ }
165
+
166
+ wantCustomRole := & CustomOrgRoles {
167
+ ID : Int64 (123456 ),
168
+ Name : String ("test-role" ),
169
+ Description : String ("test-role" ),
170
+ Permissions : []string {
171
+ "read_organization_custom_org_role" ,
172
+ "read_organization_custom_repo_role" ,
173
+ "write_organization_custom_org_role" ,
174
+ },
175
+ CreatedAt : & Timestamp {referenceTime },
176
+ UpdatedAt : & Timestamp {referenceTime },
177
+ Source : String ("Organization" ),
178
+ BaseRole : nil ,
179
+ }
180
+
181
+ if ! cmp .Equal (gotCustomRole , wantCustomRole ) {
182
+ t .Errorf ("Organizations.GetOrgRole returned %+v, want %+v" , gotCustomRole , wantCustomRole )
183
+ }
184
+
185
+ const methodName = "GetOrgRole"
186
+ testBadOptions (t , methodName , func () (err error ) {
187
+ _ , _ , err = client .Organizations .GetOrgRole (ctx , "\n o" , - 8132 )
188
+ return err
189
+ })
190
+
191
+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
192
+ got , resp , err := client .Organizations .GetOrgRole (ctx , "o" , 8132 )
193
+ if got != nil {
194
+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
195
+ }
196
+ return resp , err
197
+ })
198
+ }
199
+
101
200
func TestOrganizationsService_CreateCustomOrgRole (t * testing.T ) {
102
201
client , mux , _ , teardown := setup ()
103
202
defer teardown ()
0 commit comments