-
Notifications
You must be signed in to change notification settings - Fork 2
/
input_test.go
98 lines (84 loc) · 2.5 KB
/
input_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
97
98
package ldifdiff
import (
"os"
"strconv"
"strings"
"testing"
)
func TestImportLdifFile(t *testing.T) {
entries, err := importLdifFile(testSourceLdifFile, testIgnoreAttr)
okLdifTests(t, entries, testIgnoreAttr, err)
_, err = importLdifFile(testInvalidLineContLdifFile, testIgnoreAttr)
invalidLineCont(t, err)
_, err = importLdifFile(testInvalidNoDnLdifFile, testIgnoreAttr)
invalidNoDn(t, err)
}
func TestConvertLdifStr(t *testing.T) {
entries, err := convertLdifStr(testSourceStr, testIgnoreAttr)
okLdifTests(t, entries, testIgnoreAttr, err)
_, err = convertLdifStr(testInvalidLineContStr, testIgnoreAttr)
invalidLineCont(t, err)
entries, err = convertLdifStr(testInvalidNoDnStr, testIgnoreAttr)
invalidNoDn(t, err)
}
func TestImportLdifFileBig(t *testing.T) {
if os.Getenv(testBigFilesEnv) != testBigFilesEnvValue {
t.Skip("Skipping big files test")
}
entries, err := importLdifFile(testSourceLdifFileBig, testIgnoreAttr)
okLdifTests(t, entries, testIgnoreAttr, err)
}
func TestConvertLdifStrBig(t *testing.T) {
if os.Getenv(testBigFilesEnv) != testBigFilesEnvValue {
t.Skip("Skipping big files test")
}
entries, err := convertLdifStr(testSourceStrBig, testIgnoreAttr)
okLdifTests(t, entries, testIgnoreAttr, err)
}
/* Helper test evaluation */
func okLdifTests(t *testing.T, entries entries, ignoreAttr []string, err error) {
if err != nil {
t.Error("Expected values, got error: ", err)
}
if len(entries) != testSourceNrEntries {
t.Error("Expected", testSourceNrEntries, "entries, got", strconv.Itoa(len(entries)))
}
for dn, attributes := range entries {
if !strings.HasPrefix(dn, "dn:") {
t.Error("Invalid dn:", dn)
}
for _, attr := range attributes {
if strings.HasPrefix(attr, "#") {
t.Error("Invalid comment:", attr)
}
if strings.HasPrefix(attr, " ") {
t.Error("Line continuation not correctly appended:", attr)
}
if strings.IndexAny(attr, " :") < 1 {
t.Error("Invalid attribute line:", attr)
}
}
}
if len(ignoreAttr) > 0 {
for _, attributes := range entries {
for _, attr := range attributes {
for _, ignoredAttr := range ignoreAttr {
if strings.HasPrefix(attr, ignoredAttr+":") {
t.Error("Attributed not ignored as requested:",
ignoredAttr, attr)
}
}
}
}
}
}
func invalidLineCont(t *testing.T, err error) {
if err == nil {
t.Error("Error expected (line continuation), but none received")
}
}
func invalidNoDn(t *testing.T, err error) {
if err == nil {
t.Error("Error expected (no dn), but none received")
}
}