-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles_test.go
165 lines (134 loc) · 4.44 KB
/
files_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package main
import (
"fmt"
"testing"
)
func TestFileExists(t *testing.T) {
// The tests to run
var tests = []struct {
name string
input string
expectedResult bool
}{
{"NoParameterData", "", false},
{"FileDoesNotExist", "fakeFile", false},
{"FileExists", "TestFile", true},
}
// Set up test data
CreateFile("TestFile", 10)
// Write name of function being tested to test results file
LogResult("FileExists")
// Run the tests
for _, currentTest := range tests {
testname := fmt.Sprintf("%s", currentTest.name)
t.Run(testname, func(t *testing.T) {
result := FileExists(currentTest.input)
if result != currentTest.expectedResult {
LogResult(currentTest.name + " - " + fmt.Sprintf("Input: %s Got: %t Expected: %t", currentTest.input, result, currentTest.expectedResult) + " - FAIL")
} else {
LogResult(currentTest.name + " - " + fmt.Sprintf("Input: %s Got: %t Expected: %t", currentTest.input, result, currentTest.expectedResult) + " - PASS")
}
})
}
// Clean up test data
DeleteFile("TestFile")
}
func TestGetFileSize(t *testing.T) {
// The tests to run
var tests = []struct {
name string
input string
expectedResult int64
}{
{"NoParameterData", "", -1},
{"FileDoesNotExist", "fakeFile", -1},
{"1ByteFile", "1ByteFile", 1},
{"100ByteFile", "100ByteFile", 100},
}
// Set up test data
CreateFile("1ByteFile", 1)
CreateFile("100ByteFile", 100)
// Write name of function being tested to test results file
LogResult("GetFileSize")
// Run the tests
for _, currentTest := range tests {
testname := fmt.Sprintf("%s", currentTest.name)
t.Run(testname, func(t *testing.T) {
result := GetFileSize(currentTest.input)
if result != currentTest.expectedResult {
LogResult(currentTest.name + " - " + fmt.Sprintf("Input: %s Got: %d Expected: %d", currentTest.input, result, currentTest.expectedResult) + " - FAIL")
} else {
LogResult(currentTest.name + " - " + fmt.Sprintf("Input: %s Got: %d Expected: %d", currentTest.input, result, currentTest.expectedResult) + " - PASS")
}
})
}
// Clean up test data
DeleteFile("1ByteFile")
DeleteFile("100ByteFile")
}
func TestDeleteFile(t *testing.T) {
// The tests to run
var tests = []struct {
name string
input string
expectedResult bool
}{
{"NoParameterData", "", true},
{"FileDoesNotExist", "fakeFile", true},
{"FileExists", "TestFile", false},
}
// Set up test data
CreateFile("TestFile", 10)
// Write name of function being tested to test results file
LogResult("DeleteFile")
// Run the tests
for _, currentTest := range tests {
testname := fmt.Sprintf("%s", currentTest.name)
t.Run(testname, func(t *testing.T) {
result := DeleteFile(currentTest.input)
if result != currentTest.expectedResult {
LogResult(currentTest.name + " - " + fmt.Sprintf("Input: %s Got: %t Expected: %t", currentTest.input, result, currentTest.expectedResult) + " - FAIL")
} else {
LogResult(currentTest.name + " - " + fmt.Sprintf("Input: %s Got: %t Expected: %t", currentTest.input, result, currentTest.expectedResult) + " - PASS")
}
})
}
}
func TestWipeFile(t *testing.T) {
// The tests to run
var tests = []struct {
name string
input string
expectedResult bool
}{
{"NoParameterData", "", false},
{"FileDoesNotExist", "fakeFile", false},
{"FileExists10", "TestFile10", true},
{"FileExists100", "TestFile100", true},
{"FileExists1000", "TestFile1000", true},
{"FileExists1234", "TestFile1234", true},
{"FileExists5678", "TestFile5678", true},
{"FileExists98765", "TestFile98765", true},
}
// Set up test data
CreateFile("TestFile10", 10)
CreateFile("TestFile100", 100)
CreateFile("TestFile1000", 1000)
CreateFile("TestFile1234", 1234)
CreateFile("TestFile5678", 5678)
CreateFile("TestFile98765", 98765)
// Write name of function being tested to test results file
LogResult("WipeFile")
// Run the tests
for _, currentTest := range tests {
testname := fmt.Sprintf("%s", currentTest.name)
t.Run(testname, func(t *testing.T) {
result := WipeFile(currentTest.input)
if result != currentTest.expectedResult {
LogResult(currentTest.name + " - " + fmt.Sprintf("Input: %s Got: %t Expected: %t", currentTest.input, result, currentTest.expectedResult) + " - FAIL")
} else {
LogResult(currentTest.name + " - " + fmt.Sprintf("Input: %s Got: %t Expected: %t", currentTest.input, result, currentTest.expectedResult) + " - PASS")
}
})
}
}