2015-06-12 23:24:54 -05:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2015-06-13 05:26:29 -05:00
|
|
|
|
|
|
|
"github.com/mholt/caddy/middleware/extensions"
|
2015-06-12 23:24:54 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestExt(t *testing.T) {
|
|
|
|
c := newTestController(`ext .html .htm .php`)
|
|
|
|
|
|
|
|
mid, err := Ext(c)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected no errors, got: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if mid == nil {
|
|
|
|
t.Fatal("Expected middleware, was nil instead")
|
|
|
|
}
|
|
|
|
|
|
|
|
handler := mid(emptyNext)
|
2015-06-13 05:26:29 -05:00
|
|
|
myHandler, ok := handler.(extensions.Ext)
|
|
|
|
|
2015-06-12 23:24:54 -05:00
|
|
|
if !ok {
|
|
|
|
t.Fatalf("Expected handler to be type Ext, got: %#v", handler)
|
|
|
|
}
|
2015-06-13 09:55:23 -05:00
|
|
|
|
2015-06-13 05:26:29 -05:00
|
|
|
if myHandler.Extensions[0] != ".html" {
|
|
|
|
t.Errorf("Expected .html in the list of Extensions")
|
|
|
|
}
|
|
|
|
if myHandler.Extensions[1] != ".htm" {
|
|
|
|
t.Errorf("Expected .htm in the list of Extensions")
|
|
|
|
}
|
|
|
|
if myHandler.Extensions[2] != ".php" {
|
|
|
|
t.Errorf("Expected .php in the list of Extensions")
|
2015-06-12 23:24:54 -05:00
|
|
|
}
|
2015-06-13 09:55:23 -05:00
|
|
|
if !sameNext(myHandler.Next, emptyNext) {
|
|
|
|
t.Error("'Next' field of handler was not set properly")
|
|
|
|
}
|
|
|
|
|
2015-06-13 05:26:29 -05:00
|
|
|
|
2015-06-12 23:35:42 -05:00
|
|
|
}
|