0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2025-01-13 22:51:08 -05:00
caddy/middleware/middleware_test.go
Zac Bergquist e158cda057 Fix test failures on Windows.
Most of the Windows test failures are due to the path separator not being "/".  The general approach I took here was to keep paths in "URL form" (ie using "/" separators) as much as possible, and only convert to native paths when we attempt to open a file.  This will allow the most consistency between different host OS.  For example, data structures that store paths still store them with "/" delimiters.  Functions that accepted paths as input and return them as outputs still use "/".

There are still a few test failures that need to be sorted out.

- config/setup/TestRoot (I hear this has already been fixed by someone else)
- middleware/basicauth/TestBrowseTemplate and middleware/templates/Test (a line endings issue that I'm still working through)
2015-10-13 19:49:53 -04:00

46 lines
1.3 KiB
Go

package middleware
import (
"fmt"
"net/http"
"testing"
)
func TestIndexfile(t *testing.T) {
tests := []struct {
rootDir http.FileSystem
fpath string
indexFiles []string
shouldErr bool
expectedFilePath string //retun value
expectedBoolValue bool //return value
}{
{
http.Dir("./templates/testdata"),
"/images/",
[]string{"img.htm"},
false,
"/images/img.htm",
true,
},
}
for i, test := range tests {
actualFilePath, actualBoolValue := IndexFile(test.rootDir, test.fpath, test.indexFiles)
fmt.Println("ZBZB IndexFile returned", actualFilePath, ",", actualBoolValue)
if actualBoolValue == true && test.shouldErr {
t.Errorf("Test %d didn't error, but it should have", i)
} else if actualBoolValue != true && !test.shouldErr {
t.Errorf("Test %d errored, but it shouldn't have; got %s", i, "Please Add a / at the end of fpath or the indexFiles doesnt exist")
}
if actualFilePath != test.expectedFilePath {
t.Fatalf("Test %d expected returned filepath to be %s, but got %s ",
i, test.expectedFilePath, actualFilePath)
}
if actualBoolValue != test.expectedBoolValue {
t.Fatalf("Test %d expected returned bool value to be %v, but got %v ",
i, test.expectedBoolValue, actualBoolValue)
}
}
}