chore: added basic server startup test (#817)

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
Alex Jones
2023-12-29 14:15:32 +00:00
committed by GitHub
parent fcd29a547d
commit 3e7cea7bd3
2 changed files with 47 additions and 0 deletions

41
pkg/server/server_test.go Normal file
View File

@@ -0,0 +1,41 @@
package server
import (
"github.com/fatih/color"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"os"
"sync"
"testing"
)
func TestServerInit(t *testing.T) {
logger, err := zap.NewDevelopment()
if err != nil {
color.Red("failed to create logger: %v", err)
os.Exit(1)
}
defer logger.Sync()
server_config := Config{
Backend: "openai",
Port: "0",
MetricsPort: "0",
Token: "none",
Logger: logger,
}
var wg sync.WaitGroup
go func() {
wg.Add(1)
err := server_config.Serve()
if err != nil {
assert.Fail(t, "serve: %s", err.Error())
}
server_config.Shutdown()
if err != nil {
assert.Fail(t, "shutdown: %s", err.Error())
}
wg.Done()
}()
wg.Wait()
}