test(refactor): cleanup/simplify testcases (#1124)

Signed-off-by: Nicol Draghici <idraghic@cisco.com>
This commit is contained in:
Nicol
2023-01-20 20:01:52 +02:00
committed by GitHub
parent 70a60b4660
commit f0d947809b
9 changed files with 144 additions and 392 deletions
+4 -24
View File
@@ -5,7 +5,6 @@ package log_test
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
@@ -49,10 +48,7 @@ type AuditLog struct {
func TestAuditLogMessages(t *testing.T) {
Convey("Make a new controller", t, func() {
dir := t.TempDir()
err := CopyFiles("../../test/data", dir)
if err != nil {
panic(err)
}
CopyTestFiles("../../test/data", dir)
port := GetFreePort()
baseURL := GetBaseURL(port)
@@ -74,26 +70,10 @@ func TestAuditLogMessages(t *testing.T) {
ctlr := api.NewController(conf)
ctlr.Config.Storage.RootDirectory = dir
go func() {
// this blocks
if err := ctlr.Run(context.Background()); err != nil {
return
}
}()
// wait till ready
for {
_, err := resty.R().Get(baseURL)
if err == nil {
break
}
time.Sleep(100 * time.Millisecond)
}
defer func() {
ctx := context.Background()
_ = ctlr.Server.Shutdown(ctx)
}()
ctlrManager := NewControllerManager(ctlr)
ctlrManager.StartAndWait(port)
defer ctlrManager.StopServer()
Convey("Open auditLog file", func() {
auditFile, err := os.Open(auditPath)