-
Notifications
You must be signed in to change notification settings - Fork 2
/
generic_test.go
96 lines (89 loc) · 4.14 KB
/
generic_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package ldifdiff
import (
"io/ioutil"
"os"
"strings"
)
//* Test data */
const testBigFilesEnv = "LDIFDIFF_BIGFILES"
const testBigFilesEnvValue = "1"
const testDn = "dn: some_dn,ou=aAccounts,dc=domain,dc=ext"
const testSourceLdifFile = "t/source.ldif"
const testTargetLdifFile = "t/target.ldif"
const testResultLdifFile = "t/result.ldif"
const testResultDnFile = "t/result_dn"
const testResultDnIgnoreAttrFile = "t/result_dn_ignore_attr"
const testInvalidLineContLdifFile = "t/invalid_line_continuation.ldif"
const testInvalidNoDnLdifFile = "t/invalid_no_dn.ldif"
const testSourceLdifFileBig = "t/_source_big.ldif"
const testTargetLdifFileBig = "t/_target_big.ldif"
const testResultLdifFileBig = "t/_result_big.ldif"
const testModifyAddLdifFile = "t/modifyAdd.ldif"
const testModifyDeleteLdifFile = "t/modifyDelete.ldif"
const testModifyReplaceLdifFile = "t/modifyReplace.ldif"
const testModifyLdifFile = "t/modify.ldif"
var testSourceStr = testGetLdifeStr(testSourceLdifFile, false)
var testSourceNrEntries = testGetNrOfEntries(testSourceStr)
var testTargetStr = testGetLdifeStr(testTargetLdifFile, false)
var testResultStr = testGetLdifeStr(testResultLdifFile, false)
var testResultDnStr = testGetLdifeStr(testResultDnFile, false)
var testResultDnIgnoreAttrStr = testGetLdifeStr(testResultDnIgnoreAttrFile, false)
var testInvalidLineContStr = testGetLdifeStr(testInvalidLineContLdifFile, false)
var testInvalidNoDnStr = testGetLdifeStr(testInvalidNoDnLdifFile, false)
var testSourceStrBig = testGetLdifeStr(testSourceLdifFileBig, true)
var testTargetStrBig = testGetLdifeStr(testTargetLdifFileBig, true)
var testResultStrBig = testGetLdifeStr(testResultLdifFileBig, true)
var testModifyAddStr = testGetLdifeStr(testModifyAddLdifFile, false)
var testModifyDeleteStr = testGetLdifeStr(testModifyDeleteLdifFile, false)
var testModifyReplaceStr = testGetLdifeStr(testModifyReplaceLdifFile, false)
var testModifyStr = testGetLdifeStr(testModifyLdifFile, false)
var testIgnoreAttr = []string{"sambaSID", "eduPersonEntitlement"}
var testIgnoreAttrDn = []string{"sambaSID", "eduPersonEntitlement", "mail"}
var testAttrList = []string{"mail: auth2@domain.ext", "phone: +32364564645"}
var testAttrListModifyReplace = []string{testAttrList[0]}
var testActionEntryTestData = testGetActionEntryMap()
/* Helper functions and types */
type TestActionEntryData struct {
Add, Delete, Modify, ModifyOnlyAdd,
ModifyOnlyDelete, ModifyOnlyReplace,
ModifyNone, ModifyReplaceAttributes actionEntry
}
func testGetActionEntryMap() TestActionEntryData {
return TestActionEntryData{
Add: actionEntry{Dn: testDn, Action: actionAdd,
SubActionAttrs: []subActionAttrs{{subActionNone: testAttrList}}},
Delete: actionEntry{Dn: testDn, Action: actionDelete,
SubActionAttrs: []subActionAttrs{{subActionNone: testAttrList}}},
Modify: actionEntry{Dn: testDn, Action: actionModify,
SubActionAttrs: []subActionAttrs{
{subActionModifyAdd: testAttrList},
{subActionModifyDelete: testAttrList},
{subActionModifyReplace: testAttrListModifyReplace}}},
ModifyOnlyAdd: actionEntry{Dn: testDn, Action: actionModify,
SubActionAttrs: []subActionAttrs{{subActionModifyAdd: testAttrList}}},
ModifyOnlyDelete: actionEntry{Dn: testDn, Action: actionModify,
SubActionAttrs: []subActionAttrs{{subActionModifyDelete: testAttrList}}},
ModifyOnlyReplace: actionEntry{Dn: testDn, Action: actionModify,
SubActionAttrs: []subActionAttrs{{subActionModifyReplace: testAttrListModifyReplace}}},
ModifyNone: actionEntry{Dn: testDn, Action: actionModify,
SubActionAttrs: []subActionAttrs{{subActionNone: testAttrList}}},
ModifyReplaceAttributes: actionEntry{Dn: testDn, Action: actionModify,
SubActionAttrs: []subActionAttrs{{subActionModifyReplace: testAttrList}}},
}
}
func testGetLdifeStr(file string, big bool) string {
if big && os.Getenv(testBigFilesEnv) != testBigFilesEnvValue {
return ""
}
bytes, _ := ioutil.ReadFile(file)
return string(bytes) + "\n"
}
func testGetNrOfEntries(ldifStr string) int {
var counter int
for _, line := range strings.Split(ldifStr, "\n") {
if strings.HasPrefix(line, "dn:") {
counter++
}
}
return counter
}