0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00
caddy/caddyhttp/index/index_test.go
elcore a56a833423 caddyhttp: New index directive for alternate index file names (#1567)
* caddyhttp: Allow to alternate Index

* Move Index directive

* Fix misspelling outside this PR
2017-04-17 11:02:44 -06:00

39 lines
870 B
Go

package index
import (
"testing"
"github.com/mholt/caddy"
"github.com/mholt/caddy/caddyhttp/staticfiles"
)
func TestIndexIncompleteParams(t *testing.T) {
c := caddy.NewTestController("", "index")
err := setupIndex(c)
if err == nil {
t.Error("Expected an error, but didn't get one")
}
}
func TestIndex(t *testing.T) {
c := caddy.NewTestController("", "index a.html b.html c.html")
err := setupIndex(c)
if err != nil {
t.Errorf("Expected no errors, got: %v", err)
}
expectedIndex := []string{"a.html", "b.html", "c.html"}
if len(staticfiles.IndexPages) != 3 {
t.Errorf("Expected 3 values, got %v", len(staticfiles.IndexPages))
}
// Ensure ordering is correct
for i, actual := range staticfiles.IndexPages {
if actual != expectedIndex[i] {
t.Errorf("Expected value in position %d to be %v, got %v", i, expectedIndex[i], actual)
}
}
}