-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader_test.go
More file actions
55 lines (43 loc) · 850 Bytes
/
reader_test.go
File metadata and controls
55 lines (43 loc) · 850 Bytes
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
package main
import (
"strings"
"testing"
"fmt"
)
func TestFormatBytes(t *testing.T) {
a:=`POST /coffee HTTP/1.1
Host: localhost:42069
User-Agent: curl/7.81.0
Accept: */ /*
Content-Length: 21
{"flavor":"dark mode"}
`
buff := formatBytes([]byte(a))
result:=strings.Join(buff,"\n")
if strings.TrimSpace(a)!=result{
t.Errorf("expected %s, got %s", a,result)
}
}
func TestHeaderParser(t *testing.T){
a:=`POST /coffee HTTP/1.1
Host: localhost:42069
User-Agent: curl/7.81.0
Accept: */ /*
Content-Length: 21`
b:=strings.Split(a, "\n")
sline:=StartLine{
method: "POST",
path: "/coffee",
version: "HTTP/1.1",
}
startline,err,contlen:=HeaderParser(b)
if err!=nil{
fmt.Println("yo")
}
if startline!=sline{
t.Errorf("expected POST, got %s",startline.method )
}
if contlen!=21{
t.Errorf("expected a 21, got %s",startline.version)
}
}