2022-06-11 21:17:43 +00:00
|
|
|
//go:build integration
|
|
|
|
// +build integration
|
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-12 03:06:26 +00:00
|
|
|
"log"
|
2022-06-11 21:17:43 +00:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
2024-02-15 16:08:29 +00:00
|
|
|
|
|
|
|
cmd "codeberg.org/codeberg/pages/cli"
|
|
|
|
"codeberg.org/codeberg/pages/server"
|
2022-06-11 21:17:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2022-08-12 03:06:26 +00:00
|
|
|
log.Println("=== TestMain: START Server ===")
|
2022-06-11 21:17:43 +00:00
|
|
|
serverCtx, serverCancel := context.WithCancel(context.Background())
|
|
|
|
if err := startServer(serverCtx); err != nil {
|
2022-08-12 03:06:26 +00:00
|
|
|
log.Fatalf("could not start server: %v", err)
|
2022-06-11 21:17:43 +00:00
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
serverCancel()
|
2023-03-11 05:07:17 +00:00
|
|
|
log.Println("=== TestMain: Server STOPPED ===")
|
2022-06-11 21:17:43 +00:00
|
|
|
}()
|
|
|
|
|
2022-06-14 18:35:11 +00:00
|
|
|
time.Sleep(10 * time.Second)
|
2022-06-11 21:17:43 +00:00
|
|
|
|
2022-11-15 15:15:11 +00:00
|
|
|
m.Run()
|
2022-06-11 21:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func startServer(ctx context.Context) error {
|
2024-02-15 16:08:29 +00:00
|
|
|
args := []string{"integration"}
|
2022-06-11 21:17:43 +00:00
|
|
|
setEnvIfNotSet("ACME_API", "https://acme.mock.directory")
|
|
|
|
setEnvIfNotSet("PAGES_DOMAIN", "localhost.mock.directory")
|
|
|
|
setEnvIfNotSet("RAW_DOMAIN", "raw.localhost.mock.directory")
|
2023-02-14 03:03:00 +00:00
|
|
|
setEnvIfNotSet("PAGES_BRANCHES", "pages,main,master")
|
2022-06-11 21:17:43 +00:00
|
|
|
setEnvIfNotSet("PORT", "4430")
|
2023-02-14 02:23:28 +00:00
|
|
|
setEnvIfNotSet("HTTP_PORT", "8880")
|
|
|
|
setEnvIfNotSet("ENABLE_HTTP_SERVER", "true")
|
2023-02-10 03:00:14 +00:00
|
|
|
setEnvIfNotSet("DB_TYPE", "sqlite3")
|
2024-02-15 16:08:29 +00:00
|
|
|
setEnvIfNotSet("GITEA_ROOT", "https://codeberg.org")
|
|
|
|
setEnvIfNotSet("LOG_LEVEL", "trace")
|
|
|
|
setEnvIfNotSet("ENABLE_LFS_SUPPORT", "true")
|
|
|
|
setEnvIfNotSet("ENABLE_SYMLINK_SUPPORT", "true")
|
|
|
|
setEnvIfNotSet("ACME_ACCOUNT_CONFIG", "integration/acme-account.json")
|
2022-06-11 21:17:43 +00:00
|
|
|
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "pages-server"
|
2024-02-15 16:08:29 +00:00
|
|
|
app.Action = server.Serve
|
2023-02-10 03:00:14 +00:00
|
|
|
app.Flags = cmd.ServerFlags
|
2022-06-11 21:17:43 +00:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
if err := app.RunContext(ctx, args); err != nil {
|
2022-08-12 03:06:26 +00:00
|
|
|
log.Fatalf("run server error: %v", err)
|
2022-06-11 21:17:43 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func setEnvIfNotSet(key, value string) {
|
|
|
|
if _, set := os.LookupEnv(key); !set {
|
|
|
|
os.Setenv(key, value)
|
|
|
|
}
|
|
|
|
}
|