-
Notifications
You must be signed in to change notification settings - Fork 2
/
ldifConvertor_test.go
79 lines (68 loc) · 1.92 KB
/
ldifConvertor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package ldifdiff
import (
"bytes"
"sync"
"testing"
)
func TestCreateModifyStr(t *testing.T) {
// Regular use
modifyLdif, _ := createModifyStr(testActionEntryTestData.ModifyOnlyAdd)
if modifyLdif != testModifyAddStr {
t.Error("Expected:\n[" + testModifyAddStr + "]\nGot:\n[" + modifyLdif + "]\n")
}
modifyLdif, _ = createModifyStr(testActionEntryTestData.ModifyOnlyDelete)
if modifyLdif != testModifyDeleteStr {
t.Error("Expected:\n[" + testModifyAddStr + "]\nGot:\n[" + modifyLdif + "]\n")
}
modifyLdif, _ = createModifyStr(testActionEntryTestData.ModifyOnlyReplace)
if modifyLdif != testModifyReplaceStr {
t.Error("Expected:\n[" + testModifyAddStr + "]\nGot:\n[" + modifyLdif + "]\n")
}
// Errors
_, err := createModifyStr(testActionEntryTestData.ModifyNone)
if err == nil {
t.Error("Invalid Subaction subActionNone for action actionModify")
}
}
func TestWriteLdif(t *testing.T) {
var buffer bytes.Buffer
var wg sync.WaitGroup
var err error
queue := make(chan actionEntry)
wg.Add(2)
go func(queue chan actionEntry) {
queue <- testActionEntryTestData.Add
queue <- testActionEntryTestData.Delete
queue <- testActionEntryTestData.Modify
close(queue)
wg.Done()
}(queue)
go writeLdif(queue, &buffer, &wg, &err)
wg.Wait()
if err != nil {
t.Error("Error not expected, got: ", err)
}
ldif := buffer.String()
if ldif != testModifyStr {
t.Error("Expected:\n[" + testModifyStr + "]\nGot:\n[" + ldif + "]\n")
}
}
func TestWriteLdifError(t *testing.T) {
var buffer bytes.Buffer
var wg sync.WaitGroup
var err error
queue := make(chan actionEntry)
wg.Add(2)
go func(queue chan actionEntry) {
actionEntry := actionEntry{Dn: testDn, Action: 100,
SubActionAttrs: []subActionAttrs{{subActionNone: testAttrList}}}
queue <- actionEntry
close(queue)
wg.Done()
}(queue)
go writeLdif(queue, &buffer, &wg, &err)
wg.Wait()
if err == nil {
t.Error("Error expected for invalid action")
}
}