pages-server/integration/main_test.go

48 lines
946 B
Go

package integration
import (
"context"
"log"
"testing"
"time"
"codeberg.org/codeberg/pages/cmd"
"github.com/urfave/cli/v2"
)
func TestMain(m *testing.M) {
log.Println("=== TestMain: START Server ==")
serverCtx, serverCancel := context.WithCancel(context.Background())
if err := startServer(serverCtx); err != nil {
log.Fatalf("could not start server: %v", err)
}
defer func() {
serverCancel()
log.Println("=== TestMain: Server STOPED ==")
}()
time.Sleep(30 * time.Second)
m.Run()
}
func startServer(ctx context.Context) error {
args := []string{
"--verbose",
"--acme-accept-terms", "true",
"--acme-api-endpoint", "https://acme.mock.directory",
"--pages-domain", "localhost.mock.directory",
"--raw-domain", "raw.localhost.mock.directory",
"--port", "4430",
}
app := cli.NewApp()
app.Name = "pages-server"
app.Action = cmd.Serve
app.Flags = cmd.ServeFlags
go app.RunContext(ctx, args)
return nil
}