Addressed reviews on tests
This commit is contained in:
parent
db11f77396
commit
5f57feab54
|
@ -13,6 +13,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -1045,31 +1046,57 @@ func TestAPILogging(t *testing.T) {
|
||||||
cfg := &Config{}
|
cfg := &Config{}
|
||||||
cfg.Default()
|
cfg.Default()
|
||||||
|
|
||||||
cfg.HTTPLogFile = "/tmp/http.log"
|
baseDir, err := filepath.Abs("")
|
||||||
|
|
||||||
rest := testAPIwithConfig(t, cfg, "log_enabled")
|
|
||||||
defer rest.Shutdown(ctx)
|
|
||||||
defer os.Remove(cfg.HTTPLogFile)
|
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(cfg.HTTPLogFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
cfg.BaseDir = baseDir
|
||||||
|
cfg.HTTPLogFile = "http.log"
|
||||||
|
|
||||||
if len(data) > 0 {
|
rest := testAPIwithConfig(t, cfg, "log_enabled")
|
||||||
t.Errorf("expected empty log file, %+v", data)
|
defer os.Remove(cfg.HTTPLogFile)
|
||||||
|
|
||||||
|
info, err := os.Stat(cfg.HTTPLogFile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if info.Size() > 0 {
|
||||||
|
t.Errorf("expected empty log file")
|
||||||
}
|
}
|
||||||
|
|
||||||
id := api.ID{}
|
id := api.ID{}
|
||||||
makeGet(t, rest, httpURL(rest)+"/id", &id)
|
makeGet(t, rest, httpURL(rest)+"/id", &id)
|
||||||
|
|
||||||
data, err = ioutil.ReadFile(cfg.HTTPLogFile)
|
info, err = os.Stat(cfg.HTTPLogFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if len(data) == 0 {
|
size1 := info.Size()
|
||||||
|
if size1 == 0 {
|
||||||
t.Error("did not expect an empty log file")
|
t.Error("did not expect an empty log file")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restart API and make sure that logs are being appended
|
||||||
|
rest.Shutdown(ctx)
|
||||||
|
|
||||||
|
rest = testAPIwithConfig(t, cfg, "log_enabled")
|
||||||
|
defer rest.Shutdown(ctx)
|
||||||
|
|
||||||
|
makeGet(t, rest, httpURL(rest)+"/id", &id)
|
||||||
|
|
||||||
|
info, err = os.Stat(cfg.HTTPLogFile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
size2 := info.Size()
|
||||||
|
if size2 == 0 {
|
||||||
|
t.Error("did not expect an empty log file")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !(size2 > size1) {
|
||||||
|
t.Error("logs were not appended")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotFoundHandler(t *testing.T) {
|
func TestNotFoundHandler(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user