diff --git a/.travis.yml b/.travis.yml index 8fdcc97..7f67b8b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ services: - docker script: - - go test -race -coverprofile=coverage.txt -covermode=atomic -coverpkg . + - go test -v -race -coverprofile=coverage.txt -covermode=atomic -coverpkg . - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD` -s -w" - gox -os "linux darwin windows" -arch "amd64" -osarch="windows/386" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD` -s -w" diff --git a/main.go b/main.go index 7b41f4d..41cc4bc 100644 --- a/main.go +++ b/main.go @@ -77,8 +77,8 @@ func showVersion() { } func fileExists(p string) bool { - _, err := os.Stat(p) - return !os.IsNotExist(err) + fileInfo, err := os.Stat(p) + return !os.IsNotExist(err) && !fileInfo.IsDir() } func init() { @@ -98,7 +98,7 @@ func init() { } log.Printf("[-] [-] [INIT] [-] [-] [-] [-] [-] [-] [Users file is \"%s\"]\n", users) if !fileExists(users) && !guestAccessAllowed { - log.Fatalf("[-] [-] [INIT] [-] [-] [-] [-] [-] [-] [Users file \"%s\" does not exist]\n", users) + log.Fatalf("[-] [-] [INIT] [-] [-] [-] [-] [-] [-] [Users file \"%s\" does not exist or is a directory]\n", users) } if err := loadQuotaFiles(quotaDir); err != nil { log.Fatalf("[-] [-] [INIT] [-] [-] [-] [-] [-] [-] [%v]\n", err) diff --git a/proxy_test.go b/proxy_test.go index 4d55048..7fff8f4 100644 --- a/proxy_test.go +++ b/proxy_test.go @@ -22,6 +22,8 @@ import ( . "github.com/aandryashin/matchers" . "github.com/aandryashin/matchers/httpresp" "golang.org/x/net/websocket" + "os" + "path/filepath" ) var ( @@ -1443,3 +1445,12 @@ func doHTTPRequestWithoutAuthentication(method string, url string, body io.Reade client := &http.Client{} return client.Do(req) } + +func TestFileExists(t *testing.T) { + tmpDir := os.TempDir() + AssertThat(t, fileExists(tmpDir), Is{false}) + AssertThat(t, fileExists(filepath.Join(tmpDir, "missing-file")), Is{false}) + f, err := ioutil.TempFile(tmpDir, "testfile") + AssertThat(t, err, Is{nil}) + AssertThat(t, fileExists(f.Name()), Is{true}) +} \ No newline at end of file