You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.0 KiB
86 lines
2.0 KiB
package gopher
|
|
|
|
import (
|
|
"testing"
|
|
"os"
|
|
)
|
|
|
|
func TestNewResponse(t *testing.T) {
|
|
d, _ := os.Getwd()
|
|
c := Context { Root: d + "/../testdata" }
|
|
|
|
// root gophermap
|
|
rq, _ := NewRequest(c, "")
|
|
rs := NewResponse(c, *rq)
|
|
|
|
var expectedType ResponseType = PlainText
|
|
|
|
if rs.Type != expectedType {
|
|
t.Errorf("Unexpected type for Response for %s, expected %d, got %d", rq.Path, expectedType, rs.Type)
|
|
}
|
|
|
|
rq, _ = NewRequest(c, "/")
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expectedType = PlainText
|
|
|
|
if rs.Type != expectedType {
|
|
t.Errorf("Unexpected type for Response %s, expected %d, got %d", rq.Path, expectedType, rs.Type)
|
|
}
|
|
|
|
rq, _ = NewRequest(c, "/attic")
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expectedType = PlainText
|
|
|
|
if rs.Type != expectedType {
|
|
t.Errorf("Unexpected type for Response for %s, expected %d, got %d", rq.Path, expectedType, rs.Type)
|
|
}
|
|
|
|
rq, _ = NewRequest(c, "/attic/Goblin_Market")
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expectedType = PlainText
|
|
|
|
if rs.Type != expectedType {
|
|
t.Errorf("Unexpected type for Response for %s, expected %d, got %d", rq.Path, expectedType, rs.Type)
|
|
}
|
|
|
|
rq, _ = NewRequest(c, "/attic/pictures/starry_night.jpg")
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expectedType = Image
|
|
|
|
if rs.Type != expectedType {
|
|
t.Errorf("Unexpected type for Response for %s, expected %d, got %d", rq.Path, expectedType, rs.Type)
|
|
}
|
|
|
|
rq, _ = NewRequest(c, "/attic/pictures/hamtori.gif")
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expectedType = Image
|
|
|
|
if rs.Type != expectedType {
|
|
t.Errorf("Unexpected type for Response for %s, expected %d, got %d", rq.Path, expectedType, rs.Type)
|
|
}
|
|
|
|
rq, _ = NewRequest(c, "/attic/audio/Bubbles-SoundBible.com-810959520.mp3")
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expectedType = Audio
|
|
|
|
if rs.Type != expectedType {
|
|
t.Errorf("Unexpected type for Response for %s, expected %d, got %d", rq.Path, expectedType, rs.Type)
|
|
}
|
|
|
|
rq, _ = NewRequest(c, "/attic/blob")
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expectedType = Binary
|
|
|
|
if rs.Type != expectedType {
|
|
t.Errorf("Unexpected type for Response for %s, expected %d, got %d", rq.Path, expectedType, rs.Type)
|
|
}
|
|
|
|
|
|
}
|
|
|