-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils_test.go
59 lines (48 loc) · 1.44 KB
/
utils_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
package warc
import (
"bytes"
"testing"
)
// Tests for the GetSHA1 function
func TestGetSHA1(t *testing.T) {
helloWorldSHA1 := "FKXGYNOJJ7H3IFO35FPUBC445EPOQRXN"
if GetSHA1(bytes.NewReader([]byte("hello world"))) != helloWorldSHA1 {
t.Error("Failed to generate SHA1 with GetSHA1")
}
}
// Tests for the NewRotatorSettings function
func TestNewRotatorSettings(t *testing.T) {
rotatorSettings := NewRotatorSettings()
if rotatorSettings.Prefix != "WARC" {
t.Error("Failed to set WARC rotator's filename prefix")
}
if rotatorSettings.WarcSize != 1000 {
t.Error("Failed to set WARC rotator's WARC size")
}
if rotatorSettings.OutputDirectory != "./" {
t.Error("Failed to set WARC rotator's output directory")
}
if rotatorSettings.Compression != "GZIP" {
t.Error("Failed to set WARC rotator's compression algorithm")
}
if rotatorSettings.CompressionDictionary != "" {
t.Error("Failed to set WARC rotator's compression dictionary")
}
}
// Tests for the isLineStartingWithHTTPMethod function
func TestIsHTTPRequest(t *testing.T) {
goodHTTPRequestHeaders := []string{
"GET /index.html HTTP/1.1\r",
"POST /api/login HTTP/1.1\r",
"DELETE /api/products/456 HTTP/1.1\r",
"HEAD /about HTTP/1.0\r",
"OPTIONS / HTTP/1.1\r",
"PATCH /api/item/789 HTTP/1.1\r",
"GET /images/logo.png HTTP/1.1\r",
}
for _, header := range goodHTTPRequestHeaders {
if !isHTTPRequest(header) {
t.Error("Invalid HTTP Method parsing:", header)
}
}
}