@@ -46,11 +46,11 @@ func TestIdentityDetectorMeta(t *testing.T) {
46
46
func TestIdentityDetectorConfigure (t * testing.T ) {
47
47
id := fixtureIdentityDetector ()
48
48
facts := map [string ]interface {}{}
49
- m1 := map [string ]int {}
50
- m2 := []string {}
49
+ m1 := map [string ]int {"one" : 0 }
50
+ m2 := []string {"one" }
51
51
facts [FactIdentityDetectorPeopleDict ] = m1
52
52
facts [FactIdentityDetectorReversedPeopleDict ] = m2
53
- id .Configure (facts )
53
+ assert . Nil ( t , id .Configure (facts ) )
54
54
assert .Equal (t , m1 , facts [FactIdentityDetectorPeopleDict ])
55
55
assert .Equal (t , m2 , facts [FactIdentityDetectorReversedPeopleDict ])
56
56
assert .Equal (t , id .PeopleDict , facts [FactIdentityDetectorPeopleDict ])
66
66
delete (facts , FactIdentityDetectorPeopleDict )
67
67
delete (facts , FactIdentityDetectorReversedPeopleDict )
68
68
facts [ConfigIdentityDetectorPeopleDictPath ] = tmpf .Name ()
69
- id .Configure (facts )
69
+ assert . Nil ( t , id .Configure (facts ) )
70
70
assert .Len (t , id .PeopleDict , 2 )
71
71
assert .Len (t , id .ReversedPeopleDict , 1 )
72
72
assert .Equal (t , id .ReversedPeopleDict [0 ], "Vadim" )
73
73
delete (facts , FactIdentityDetectorPeopleDict )
74
74
delete (facts , FactIdentityDetectorReversedPeopleDict )
75
75
id = fixtureIdentityDetector ()
76
76
id .PeopleDict = nil
77
- id .Configure (facts )
77
+ assert . Nil ( t , id .Configure (facts ) )
78
78
assert .Equal (t , id .PeopleDict , facts [FactIdentityDetectorPeopleDict ])
79
79
assert .Equal (t , id .ReversedPeopleDict , facts [FactIdentityDetectorReversedPeopleDict ])
80
80
assert .Len (t , id .PeopleDict , 4 )
85
85
delete (facts , FactIdentityDetectorReversedPeopleDict )
86
86
id = fixtureIdentityDetector ()
87
87
id .ReversedPeopleDict = nil
88
- id .Configure (facts )
88
+ assert . Nil ( t , id .Configure (facts ) )
89
89
assert .Equal (t , id .PeopleDict , facts [FactIdentityDetectorPeopleDict ])
90
90
assert .Equal (t , id .ReversedPeopleDict , facts [FactIdentityDetectorReversedPeopleDict ])
91
91
assert .Len (t , id .PeopleDict , 4 )
108
108
id = fixtureIdentityDetector ()
109
109
id .PeopleDict = nil
110
110
id .ReversedPeopleDict = nil
111
- id .Configure (facts )
111
+ assert . Nil ( t , id .Configure (facts ) )
112
112
assert .Equal (t , id .PeopleDict , facts [FactIdentityDetectorPeopleDict ])
113
113
assert .Equal (t , id .ReversedPeopleDict , facts [FactIdentityDetectorReversedPeopleDict ])
114
114
assert .True (t , len (id .PeopleDict ) >= 3 )
@@ -381,26 +381,59 @@ func TestIdentityDetectorGeneratePeopleDictMailmap(t *testing.T) {
381
381
382
382
}
383
383
384
- func TestIdentityDetectorMergeReversedDicts (t * testing.T ) {
385
- pa1 := [... ]string {"one" , "two" }
386
- pa2 := [... ]string {"two" , "three" }
387
- people , merged := Detector {}. MergeReversedDicts (pa1 [:], pa2 [:])
384
+ func TestIdentityDetectorMergeReversedDictsLiteral (t * testing.T ) {
385
+ pa1 := [... ]string {"one|one@one " , "two|aaa@ two" }
386
+ pa2 := [... ]string {"two|aaa@two " , "three|one@one " }
387
+ people , merged := MergeReversedDictsLiteral (pa1 [:], pa2 [:])
388
388
assert .Len (t , people , 3 )
389
389
assert .Len (t , merged , 3 )
390
- assert .Equal (t , people ["one" ], [3 ]int {0 , 0 , - 1 })
391
- assert .Equal (t , people ["two" ], [3 ]int {1 , 1 , 0 })
392
- assert .Equal (t , people ["three" ], [3 ]int {2 , - 1 , 1 })
393
- vm := [... ]string {"one" , "two" , "three" }
394
- assert .Equal (t , merged , vm [:])
395
- pa1 = [... ]string {"two" , "one" }
396
- people , merged = Detector {}.MergeReversedDicts (pa1 [:], pa2 [:])
390
+ assert .Equal (t , people ["one|one@one" ], MergedIndex {0 , 0 , - 1 })
391
+ assert .Equal (t , people ["two|aaa@two" ], MergedIndex {1 , 1 , 0 })
392
+ assert .Equal (t , people ["three|one@one" ], MergedIndex {2 , - 1 , 1 })
393
+ assert .Equal (t , merged , []string {"one|one@one" , "two|aaa@two" , "three|one@one" })
394
+ pa1 = [... ]string {"two|aaa@two" , "one|one@one" }
395
+ people , merged = MergeReversedDictsLiteral (pa1 [:], pa2 [:])
397
396
assert .Len (t , people , 3 )
398
397
assert .Len (t , merged , 3 )
399
- assert .Equal (t , people ["one" ], [3 ]int {1 , 1 , - 1 })
400
- assert .Equal (t , people ["two" ], [3 ]int {0 , 0 , 0 })
401
- assert .Equal (t , people ["three" ], [3 ]int {2 , - 1 , 1 })
402
- vm = [... ]string {"two" , "one" , "three" }
403
- assert .Equal (t , merged , vm [:])
398
+ assert .Equal (t , people ["one|one@one" ], MergedIndex {1 , 1 , - 1 })
399
+ assert .Equal (t , people ["two|aaa@two" ], MergedIndex {0 , 0 , 0 })
400
+ assert .Equal (t , people ["three|one@one" ], MergedIndex {2 , - 1 , 1 })
401
+ assert .Equal (t , merged , []string {"two|aaa@two" , "one|one@one" , "three|one@one" })
402
+ }
403
+
404
+ func TestIdentityDetectorMergeReversedDictsIdentities (t * testing.T ) {
405
+ pa1 := [... ]string {"one|one@one" , "two|aaa@two" }
406
+ pa2 := [... ]string {"two|aaa@two" , "three|one@one" }
407
+ people , merged := MergeReversedDictsIdentities (pa1 [:], pa2 [:])
408
+ assert .Len (t , people , 3 )
409
+ assert .Len (t , merged , 2 )
410
+ assert .Equal (t , people ["one|one@one" ], MergedIndex {0 , 0 , - 1 })
411
+ assert .Equal (t , people ["two|aaa@two" ], MergedIndex {1 , 1 , 0 })
412
+ assert .Equal (t , people ["three|one@one" ], MergedIndex {0 , - 1 , 1 })
413
+ assert .Equal (t , merged , []string {"one|three|one@one" , "two|aaa@two" })
414
+ }
415
+
416
+ func TestIdentityDetectorMergeReversedDictsIdentitiesStrikeBack (t * testing.T ) {
417
+ pa1 := [... ]string {"one|one@one" , "two|aaa@two" , "three|three@three" }
418
+ pa2 := [... ]string {"two|aaa@two" , "three|one@one" }
419
+ people , merged := MergeReversedDictsIdentities (pa1 [:], pa2 [:])
420
+ assert .Len (t , people , 4 )
421
+ assert .Len (t , merged , 2 )
422
+ assert .Equal (t , people ["one|one@one" ], MergedIndex {0 , 0 , - 1 })
423
+ assert .Equal (t , people ["two|aaa@two" ], MergedIndex {1 , 1 , 0 })
424
+ assert .Equal (t , people ["three|one@one" ], MergedIndex {0 , - 1 , 1 })
425
+ assert .Equal (t , people ["three|three@three" ], MergedIndex {0 , 2 , - 1 })
426
+ assert .Equal (t , merged , []string {"one|three|one@one|three@three" , "two|aaa@two" })
427
+
428
+ pa1 = [... ]string {"one|one@one" , "two|aaa@two" , "three|aaa@two" }
429
+ people , merged = MergeReversedDictsIdentities (pa1 [:], pa2 [:])
430
+ assert .Len (t , people , 4 )
431
+ assert .Len (t , merged , 1 )
432
+ assert .Equal (t , people ["one|one@one" ], MergedIndex {0 , 0 , - 1 })
433
+ assert .Equal (t , people ["two|aaa@two" ], MergedIndex {0 , 1 , 0 })
434
+ assert .Equal (t , people ["three|one@one" ], MergedIndex {0 , - 1 , 1 })
435
+ assert .Equal (t , people ["three|aaa@two" ], MergedIndex {0 , 2 , - 1 })
436
+ assert .Equal (t , merged , []string {"one|three|two|aaa@two|one@one" })
404
437
}
405
438
406
439
func TestIdentityDetectorFork (t * testing.T ) {
0 commit comments