diff options
author | 2016-03-19 07:18:57 +0000 | |
---|---|---|
committer | 2016-03-19 07:32:50 +0000 | |
commit | f907311cdf46efe7c2fad9291479e2eda495df09 (patch) | |
tree | f08ef6e2187346c415d2a64a8caf2cc369f164aa /middleware/middleware_test.go | |
parent | 523cc0a0fdbbb1da38e629c05543c1cbf8467cd1 (diff) | |
download | coredns-f907311cdf46efe7c2fad9291479e2eda495df09.tar.gz coredns-f907311cdf46efe7c2fad9291479e2eda495df09.tar.zst coredns-f907311cdf46efe7c2fad9291479e2eda495df09.zip |
Use context.Context
Rename the old Context to State and use context.Context in the
middleware for intra-middleware communication and more.
Diffstat (limited to 'middleware/middleware_test.go')
-rw-r--r-- | middleware/middleware_test.go | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/middleware/middleware_test.go b/middleware/middleware_test.go index 62fa4e250..c870d7c16 100644 --- a/middleware/middleware_test.go +++ b/middleware/middleware_test.go @@ -1,108 +1 @@ package middleware - -import ( - "fmt" - "net/http" - "net/http/httptest" - "testing" - "time" -) - -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) - 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) - - } - } -} - -func TestSetLastModified(t *testing.T) { - nowTime := time.Now() - - // ovewrite the function to return reliable time - originalGetCurrentTimeFunc := currentTime - currentTime = func() time.Time { - return nowTime - } - defer func() { - currentTime = originalGetCurrentTimeFunc - }() - - pastTime := nowTime.Truncate(1 * time.Hour) - futureTime := nowTime.Add(1 * time.Hour) - - tests := []struct { - inputModTime time.Time - expectedIsHeaderSet bool - expectedLastModified string - }{ - { - inputModTime: pastTime, - expectedIsHeaderSet: true, - expectedLastModified: pastTime.UTC().Format(http.TimeFormat), - }, - { - inputModTime: nowTime, - expectedIsHeaderSet: true, - expectedLastModified: nowTime.UTC().Format(http.TimeFormat), - }, - { - inputModTime: futureTime, - expectedIsHeaderSet: true, - expectedLastModified: nowTime.UTC().Format(http.TimeFormat), - }, - { - inputModTime: time.Time{}, - expectedIsHeaderSet: false, - }, - } - - for i, test := range tests { - responseRecorder := httptest.NewRecorder() - errorPrefix := fmt.Sprintf("Test [%d]: ", i) - SetLastModifiedHeader(responseRecorder, test.inputModTime) - actualLastModifiedHeader := responseRecorder.Header().Get("Last-Modified") - - if test.expectedIsHeaderSet && actualLastModifiedHeader == "" { - t.Fatalf(errorPrefix + "Expected to find Last-Modified header, but found nothing") - } - - if !test.expectedIsHeaderSet && actualLastModifiedHeader != "" { - t.Fatalf(errorPrefix+"Did not expect to find Last-Modified header, but found one [%s].", actualLastModifiedHeader) - } - - if test.expectedLastModified != actualLastModifiedHeader { - t.Errorf(errorPrefix+"Expected Last-Modified content [%s], found [%s}", test.expectedLastModified, actualLastModifiedHeader) - } - } -} |