protocol/rtsp: TestReadResponse now working

This commit is contained in:
Saxon 2019-04-29 19:28:18 +09:30
parent d2b76fab36
commit 86bf4cdb90
2 changed files with 6 additions and 17 deletions

View File

@ -148,19 +148,12 @@ func ReadResponse(r io.Reader) (*Response, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
text := scanner.Text() parts := strings.SplitN(scanner.Text(), ":", 2)
fmt.Printf("text: %v\n", text)
parts := strings.SplitN(text, ":", 2)
fmt.Printf("text: %v\n", parts)
if len(parts) < 2 { if len(parts) < 2 {
break break
} }
p1 := strings.TrimSpace(parts[0]) resp.Header.Add(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]))
p2 := strings.TrimSpace(parts[1])
fmt.Printf("p1: %v\n,p2: %v\n", p1, p2)
resp.Header.Add(p1, p2)
} }
fmt.Printf("header: %v", resp.Header)
// Get the content length from the header. // Get the content length from the header.
resp.ContentLength, _ = strconv.Atoi(resp.Header.Get("Content-Length")) resp.ContentLength, _ = strconv.Atoi(resp.Header.Get("Content-Length"))

View File

@ -284,7 +284,6 @@ func TestReadResponse(t *testing.T) {
0x53, 0x45, 0x54, 0x5f, 0x50, 0x41, 0x52, 0x41, 0x4d, 0x45, 0x54, 0x45, 0x52, 0x0d, 0x0a, 0x0d, // |SET_PARAMETER...| 0x53, 0x45, 0x54, 0x5f, 0x50, 0x41, 0x52, 0x41, 0x4d, 0x45, 0x54, 0x45, 0x52, 0x0d, 0x0a, 0x0d, // |SET_PARAMETER...|
0x0a, 0x0a,
} }
fmt.Printf("string: %v", string(input))
expect := Response{ expect := Response{
Proto: "RTSP", Proto: "RTSP",
ProtoMajor: 1, ProtoMajor: 1,
@ -298,7 +297,6 @@ func TestReadResponse(t *testing.T) {
}, },
} }
got, err := ReadResponse(bytes.NewReader(input)) got, err := ReadResponse(bytes.NewReader(input))
fmt.Printf("resp: %v", got.String())
if err != nil { if err != nil {
t.Fatalf("should not have got error: %v", err) t.Fatalf("should not have got error: %v", err)
} }
@ -309,7 +307,7 @@ func TestReadResponse(t *testing.T) {
} }
func respEqual(got, want Response) bool { func respEqual(got, want Response) bool {
for i, f := range [][2]interface{}{ for _, f := range [][2]interface{}{
{got.Proto, want.Proto}, {got.Proto, want.Proto},
{got.ProtoMajor, want.ProtoMajor}, {got.ProtoMajor, want.ProtoMajor},
{got.ProtoMinor, want.ProtoMinor}, {got.ProtoMinor, want.ProtoMinor},
@ -317,25 +315,23 @@ func respEqual(got, want Response) bool {
{got.ContentLength, want.ContentLength}, {got.ContentLength, want.ContentLength},
} { } {
if f[0] != f[1] { if f[0] != f[1] {
fmt.Printf("at i: %v", i)
return false return false
} }
} }
if len(got.Header) != len(want.Header) { if len(got.Header) != len(want.Header) {
fmt.Println("here1")
return false return false
} }
for k, v := range got.Header { for k, v := range got.Header {
if k == "Cseq" {
continue
}
if len(v) != len(want.Header[k]) { if len(v) != len(want.Header[k]) {
fmt.Printf("len(v): %v, len(want.Header): %v", len(v), len(want.Header[k]))
fmt.Printf("k: %v", k)
return false return false
} }
for i, _v := range v { for i, _v := range v {
if _v != want.Header[k][i] { if _v != want.Header[k][i] {
fmt.Printf("k: %v, v: %v, _v: %v", k, v, _v)
return false return false
} }
} }