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.
219 lines
5.5 KiB
219 lines
5.5 KiB
package gopher
|
|
|
|
|
|
import (
|
|
"testing"
|
|
"os"
|
|
)
|
|
|
|
func TestFullPathMatchPredicateFor(t *testing.T) {
|
|
d, _ := os.Getwd()
|
|
c := Context { Root: d + "/../testdata" }
|
|
rq, _ := NewRequest(c, "/attic/Goblin_Market")
|
|
rs := NewResponse(c, *rq)
|
|
|
|
p := "/attic"
|
|
|
|
pred := FullPathMatchPredicateFor(p)
|
|
expected := true
|
|
got := pred(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from a generated FullPathMatchPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
|
|
rq, _ = NewRequest(c, "/writings")
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expected = false
|
|
got = pred(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from a generated FullPathMatchPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
}
|
|
|
|
func TestGopherMapPredicate(t *testing.T) {
|
|
d, _ := os.Getwd()
|
|
c := Context { Root: d + "/../testdata" }
|
|
p:= ""
|
|
rq, _ := NewRequest(c, p)
|
|
rs := NewResponse(c, *rq)
|
|
|
|
expected := true
|
|
got := GopherMapPredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from GopherMapPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
|
|
p = "/attic"
|
|
rq, _ = NewRequest(c, p)
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expected = true
|
|
got = GopherMapPredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from GopherMapPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
}
|
|
|
|
func TestFileTypeBinaryPredicate(t *testing.T) {
|
|
d, _ := os.Getwd()
|
|
c := Context { Root: d + "/../testdata" }
|
|
p:= "/attic/cat"
|
|
rq, _ := NewRequest(c, p)
|
|
rs := NewResponse(c, *rq)
|
|
|
|
expected := true
|
|
got := FileTypeBinaryPredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from FileTypeBinaryPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
|
|
p = "/attic/Goblin_Market"
|
|
rq, _ = NewRequest(c, p)
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expected = false
|
|
got = FileTypeBinaryPredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from FileTypeBinaryPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
}
|
|
|
|
func TestFileTypePlainTextPredicate(t *testing.T) {
|
|
d, _ := os.Getwd()
|
|
c := Context { Root: d + "/../testdata" }
|
|
p:= "/attic/Goblin_Market"
|
|
rq, _ := NewRequest(c, p)
|
|
rs := NewResponse(c, *rq)
|
|
|
|
expected := true
|
|
got := FileTypePlainTextPredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from FileTypePlainTextPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
|
|
p = "/attic/"
|
|
rq, _ = NewRequest(c, p)
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expected = false
|
|
got = FileTypeBinaryPredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from FileTypePlainTextPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
}
|
|
|
|
func TestFileTypeAudioPredicate(t *testing.T) {
|
|
d, _ := os.Getwd()
|
|
c := Context { Root: d + "/../testdata" }
|
|
p:= "/attic/audio/Bubbles-SoundBible.com-810959520.mp3"
|
|
rq, _ := NewRequest(c, p)
|
|
rs := NewResponse(c, *rq)
|
|
|
|
expected := true
|
|
got := FileTypeAudioPredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from FileTypeAudioPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
|
|
p = "/attic/Goblin_Market"
|
|
rq, _ = NewRequest(c, p)
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expected = false
|
|
got = FileTypeAudioPredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from FileTypeAudioPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
}
|
|
|
|
func TestFileTypeImagePredicate(t *testing.T) {
|
|
d, _ := os.Getwd()
|
|
c := Context { Root: d + "/../testdata" }
|
|
p:= "/attic/pictures/hamtori.gif"
|
|
rq, _ := NewRequest(c, p)
|
|
rs := NewResponse(c, *rq)
|
|
|
|
expected := true
|
|
got := FileTypeImagePredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from FileTypeImagePredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
|
|
p = "/attic/Goblin_Market"
|
|
rq, _ = NewRequest(c, p)
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expected = false
|
|
got = FileTypeImagePredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from FileTypeImagePredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
}
|
|
|
|
func TestFileTypePDFPredicate(t *testing.T) {
|
|
d, _ := os.Getwd()
|
|
c := Context { Root: d + "/../testdata" }
|
|
p:= "/attic/rfc1436.txt.pdf"
|
|
rq, _ := NewRequest(c, p)
|
|
rs := NewResponse(c, *rq)
|
|
|
|
expected := true
|
|
got := FileTypePDFPredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from FileTypePDFPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
|
|
p = "/attic/Goblin_Market"
|
|
rq, _ = NewRequest(c, p)
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expected = false
|
|
got = FileTypePDFPredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from FileTypePDFPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
}
|
|
|
|
func TestFileTypeDocPredicate(t *testing.T) {
|
|
d, _ := os.Getwd()
|
|
c := Context { Root: d + "/../testdata" }
|
|
p:= "/attic/gopher.docx"
|
|
rq, _ := NewRequest(c, p)
|
|
rs := NewResponse(c, *rq)
|
|
|
|
expected := true
|
|
got := FileTypeDocPredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from FileTypeDocPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
|
|
p = "/attic/Goblin_Market"
|
|
rq, _ = NewRequest(c, p)
|
|
rs = NewResponse(c, *rq)
|
|
|
|
expected = false
|
|
got = FileTypePDFPredicate(c, *rq, *rs, nil)
|
|
|
|
if got != expected {
|
|
t.Errorf("Unexpected return value from FileTypeDocPredicate for path %s, expected %t, got %t", p, expected, got)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|