-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
100 lines (96 loc) · 2.64 KB
/
main_test.go
File metadata and controls
100 lines (96 loc) · 2.64 KB
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
99
100
package main
import (
"bytes"
"strings"
"testing"
)
type testCase struct {
origins string
response []string
source string
}
var TestCases = []testCase{
testCase{
origins: "TestData\\Test1.txt\nTestData\\Test2.txt\nTestData\\Test3.txt",
response: []string{
"Count for TestData\\Test3.txt: 0",
"Count for TestData\\Test1.txt: 3",
"Count for TestData\\Test2.txt: 7",
"Total: 10",
},
source: "file",
},
testCase{
origins: "https://golang.org\nhttps://golang.org\nhttps://en.wikipedia.org/wiki/Go_Go_Gophers",
response: []string{
"Count for https://en.wikipedia.org/wiki/Go_Go_Gophers: 174",
"Count for https://golang.org: 9",
"Count for https://golang.org: 9",
"Total: 192",
},
source: "url",
},
testCase{
origins: "TestData\\Test1.txt\nTestData\\Test2.txt\nTestData\\Test3.txt\nTestData\\Test1.txt\nTestData\\Test2.txt\nTestData\\Test3.txt",
response: []string{
"Count for TestData\\Test3.txt: 0",
"Count for TestData\\Test1.txt: 3",
"Count for TestData\\Test1.txt: 3",
"Count for TestData\\Test2.txt: 7",
"Count for TestData\\Test2.txt: 7",
"Count for TestData\\Test3.txt: 0",
"Total: 20",
},
source: "file",
},
testCase{
origins: "https://golang.org\nhttps://golang.org\nhttps://en.wikipedia.org/wiki/Go_Go_Gophers\nhttps://www.google.ru/\nhttps://golang.org/pkg/\nhttps://golang.org/help/",
response: []string{
"Count for https://www.google.ru/: 10",
"Count for https://en.wikipedia.org/wiki/Go_Go_Gophers: 174",
"Count for https://golang.org/pkg/: 33",
"Count for https://golang.org: 9",
"Count for https://golang.org/help/: 36",
"Count for https://golang.org: 9",
"Total: 271"},
source: "url",
},
testCase{
origins: "TestData\\Test.txt",
response: []string{
"File TestData\\Test.txt can not be open",
"Total: 0",
},
source: "file",
},
testCase{
origins: "https://golang.o",
response: []string{
"URL https://golang.o can not be open",
"Total: 0"},
source: "url",
},
}
func TestGoSearcher(t *testing.T) {
for i, item := range TestCases {
input := new(bytes.Buffer)
output := new(bytes.Buffer)
input.WriteString(item.origins)
GoSearcher(input, output, item.source)
result := strings.Split(output.String(), "\n")
if len(result) != len(item.response) {
t.Errorf("Test[%d] is failed: Result has invalid length\n Got:%d\nExpected:%d\n", i, len(result), len(item.response))
}
for _, expected := range item.response {
isEqual := false
for _, item := range result {
if item == expected {
isEqual = true
}
}
if !isEqual {
t.Errorf("Test[%d] is failed: Got:%v\nExpected:%v\n", i, result, item.response)
}
}
}
}