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