* Add a setup test for middleware/file This fix adds a setup test for middleware/file so that there is a basic coverage for the Corefile processing of middleware/file. This fix is related to 308 (Will look into it). Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * middleware/file: use helper function for test Fixup setup_test.go and use the test.TempFile function to make things somewhat shorter. Use clean up the use of testing.T in TempFile - it is not used.
19 lines
486 B
Go
19 lines
486 B
Go
package test
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
// TempFile will create a temporary file on disk and returns the name and a cleanup function to remove it later.
|
|
func TempFile(dir, content string) (string, func(), error) {
|
|
f, err := ioutil.TempFile(dir, "go-test-tmpfile")
|
|
if err != nil {
|
|
return "", nil, err
|
|
}
|
|
if err := ioutil.WriteFile(f.Name(), []byte(content), 0644); err != nil {
|
|
return "", nil, err
|
|
}
|
|
rmFunc := func() { os.Remove(f.Name()) }
|
|
return f.Name(), rmFunc, nil
|
|
}
|