|
5 | 5 | "os" |
6 | 6 | "testing" |
7 | 7 |
|
| 8 | + "github.com/go-ldap/ldap/v3" |
8 | 9 | "github.com/go-ldap/ldif" |
9 | 10 | ) |
10 | 11 |
|
@@ -286,69 +287,84 @@ func TestParseModify(t *testing.T) { |
286 | 287 | } |
287 | 288 |
|
288 | 289 | //DeleteAttributes |
289 | | - attributes := l.Entries[0].Modify.DeleteAttributes |
| 290 | + attributes := countChangeType("delete", l.Entries[0].Modify.Changes) |
290 | 291 | if actual := len(attributes); actual != 2 { |
291 | 292 | t.Error("Expected", 2, "Actual", actual) |
292 | 293 | } |
293 | 294 |
|
294 | | - if actual := attributes[0].Type; actual != "mail" { |
| 295 | + if actual := attributes[0].Modification.Type; actual != "mail" { |
295 | 296 | t.Error("Expected", "mail", "Actual", actual) |
296 | 297 | } |
297 | 298 |
|
298 | | - if actual := len(attributes[0].Vals); actual != 0 { |
| 299 | + if actual := len(attributes[0].Modification.Vals); actual != 0 { |
299 | 300 | t.Error("Expected", 0, "Actual", actual) |
300 | 301 | } |
301 | 302 |
|
302 | | - if actual := attributes[1].Type; actual != "telephoneNumber" { |
| 303 | + if actual := attributes[1].Modification.Type; actual != "telephoneNumber" { |
303 | 304 | t.Error("Expected", "telephoneNumber", "Actual", actual) |
304 | 305 | } |
305 | 306 |
|
306 | | - if actual := len(attributes[1].Vals); actual != 1 { |
| 307 | + if actual := len(attributes[1].Modification.Vals); actual != 1 { |
307 | 308 | t.Error("Expected", 1, "Actual", actual) |
308 | 309 | } |
309 | 310 |
|
310 | | - if actual := attributes[1].Vals[0]; actual != "123 456 789 - 0" { |
| 311 | + if actual := attributes[1].Modification.Vals[0]; actual != "123 456 789 - 0" { |
311 | 312 | t.Error("Expected", "123 456 789 - 0", "Actual", actual) |
312 | 313 | } |
313 | 314 |
|
314 | | - //ReplaceAttributes |
315 | | - attributes = l.Entries[0].Modify.ReplaceAttributes |
| 315 | + // //ReplaceAttributes |
| 316 | + attributes = countChangeType("replace", l.Entries[0].Modify.Changes) |
316 | 317 | if actual := len(attributes); actual != 1 { |
317 | 318 | t.Error("Expected", 1, "Actual", actual) |
318 | 319 | } |
319 | 320 |
|
320 | | - if actual := attributes[0].Type; actual != "sn" { |
| 321 | + if actual := attributes[0].Modification.Type; actual != "sn" { |
321 | 322 | t.Error("Expected", "sn", "Actual", actual) |
322 | 323 | } |
323 | 324 |
|
324 | | - if actual := len(attributes[0].Vals); actual != 1 { |
| 325 | + if actual := len(attributes[0].Modification.Vals); actual != 1 { |
325 | 326 | t.Error("Expected", 1, "Actual", actual) |
326 | 327 | } |
327 | 328 |
|
328 | | - if actual := attributes[0].Vals[0]; actual != "One" { |
| 329 | + if actual := attributes[0].Modification.Vals[0]; actual != "One" { |
329 | 330 | t.Error("Expected", "One", "Actual", actual) |
330 | 331 | } |
331 | 332 |
|
332 | | - //AddAttributes |
333 | | - attributes = l.Entries[0].Modify.AddAttributes |
| 333 | + // //AddAttributes |
| 334 | + attributes = countChangeType("add", l.Entries[0].Modify.Changes) |
334 | 335 | if actual := len(attributes); actual != 1 { |
335 | 336 | t.Error("Expected", 1, "Actual", actual) |
336 | 337 | } |
337 | 338 |
|
338 | | - if actual := attributes[0].Type; actual != "givenName" { |
| 339 | + if actual := attributes[0].Modification.Type; actual != "givenName" { |
339 | 340 | t.Error("Expected", "givenName", "Actual", actual) |
340 | 341 | } |
341 | 342 |
|
342 | | - if actual := len(attributes[0].Vals); actual != 2 { |
| 343 | + if actual := len(attributes[0].Modification.Vals); actual != 2 { |
343 | 344 | t.Error("Expected", 2, "Actual", actual) |
344 | 345 | } |
345 | 346 |
|
346 | | - if actual := attributes[0].Vals[0]; actual != "Some1" { |
| 347 | + if actual := attributes[0].Modification.Vals[0]; actual != "Some1" { |
347 | 348 | t.Error("Expected", "Some1", "Actual", actual) |
348 | 349 | } |
349 | 350 |
|
350 | | - if actual := attributes[0].Vals[1]; actual != "Some2" { |
| 351 | + if actual := attributes[0].Modification.Vals[1]; actual != "Some2" { |
351 | 352 | t.Error("Expected", "Some2", "Actual", actual) |
352 | 353 | } |
| 354 | +} |
353 | 355 |
|
| 356 | +// countChangeType is a helper function to minimise test changes migrating to ldapv3 |
| 357 | +func countChangeType(typ string, ch []ldap.Change) []ldap.Change { |
| 358 | + var t = map[string]uint{ |
| 359 | + "add": 0, |
| 360 | + "delete": 1, |
| 361 | + "replace": 2, |
| 362 | + } |
| 363 | + c := []ldap.Change{} |
| 364 | + for _, i := range ch { |
| 365 | + if i.Operation == t[typ] { |
| 366 | + c = append(c, i) |
| 367 | + } |
| 368 | + } |
| 369 | + return c |
354 | 370 | } |
0 commit comments