-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfehrist_test.go
106 lines (92 loc) · 2.39 KB
/
fehrist_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
99
100
101
102
103
104
105
106
package main
import (
"encoding/json"
"fmt"
"os"
"testing"
"github.com/kadnan/fehrist/fehrist"
)
func TestDocumentFileNotFoundCSV(t *testing.T) {
path, _ := os.Getwd()
fileName := path + "/" + "LOL.csv"
CSVDocument := &fehrist.CSV{IndexName: "local"}
indexCount, _ := CSVDocument.Index(fileName)
if indexCount != -1 {
t.Errorf("Test DocumentFileNotFound Failed")
}
}
func TestDocumentIndexedCSV(t *testing.T) {
path, _ := os.Getwd()
fileName := path + "/" + "1.csv"
CSVDocument := &fehrist.CSV{IndexName: "local"}
indexCount, err := CSVDocument.Index(fileName)
fmt.Println(indexCount)
fmt.Println(err)
if indexCount < 1 {
t.Errorf("Test Document Index Failed CSV")
}
}
func TestDocumentFileNotFoundJSON(t *testing.T) {
path, _ := os.Getwd()
fileName := path + "/" + "LOL.json"
CSVDocument := &fehrist.CSV{IndexName: "local"}
indexCount, _ := CSVDocument.Index(fileName)
if indexCount != -1 {
t.Errorf("Test Document Indexed Failed")
}
}
func TestDocumentIndexedJSON(t *testing.T) {
path, _ := os.Getwd()
fileName := path + "/" + "1.json"
JSONDocument := &fehrist.JSON{IndexName: "local"}
indexCount, _ := JSONDocument.Index(fileName)
if indexCount < 1 {
t.Errorf("Test Document Index Failed JSON")
}
}
func TestInitCSV(t *testing.T) {
Document := &fehrist.CSV{IndexName: "local"}
result := Document.Init()
if result != 1 {
t.Errorf("Test Initialization failed for CSV Document")
}
}
func TestInitJSON(t *testing.T) {
Document := &fehrist.JSON{IndexName: "local"}
result := Document.Init()
if result != 1 {
t.Errorf("Test Initialization failed for JSON Document")
}
}
func TestSearchCSVKWExist(t *testing.T) {
var input map[string]interface{}
Document := &fehrist.CSV{IndexName: "local"}
result := Document.Init()
if result == 1 {
out, _, _ := Document.Search("mango")
err := json.Unmarshal([]byte(out), &input)
if err != nil {
fmt.Println(err)
}
_, ok := input["Total"]
if !ok {
t.Errorf("Test TestSearchCSVKWExist failed for CSV Document")
}
}
}
func TestSearchJSONKWExist(t *testing.T) {
var input map[string]interface{}
Document := &fehrist.JSON{IndexName: "local"}
result := Document.Init()
if result == 1 {
out, _, _ := Document.Search("mango")
err := json.Unmarshal([]byte(out), &input)
if err != nil {
fmt.Println(err)
}
_, ok := input["Total"]
if !ok {
t.Errorf("Test TestSearchCSVKWExist failed for JSON Document")
}
}
}