Files
homarr/tools/homarr-dev/internal/run/run_test.go
T

60 lines
1.4 KiB
Go

package run
import (
"os"
"slices"
"strconv"
"testing"
"github.com/homarr-labs/homarr/tools/homarr-dev/internal/docker"
)
func TestPRPlanUsesAMD64(t *testing.T) {
plan, err := BuildPlan(Options{PR: 1, FindPort: func(int) int { return 7575 }})
if err != nil {
t.Fatal(err)
}
if plan.Platform != "linux/amd64" {
t.Fatalf("platform = %q, want linux/amd64", plan.Platform)
}
}
func TestPRCloneIsShallow(t *testing.T) {
args := prCloneArgs("/tmp/checkout")
if !slices.Contains(args, "--depth=1") || !slices.Contains(args, "--filter=blob:none") {
t.Fatalf("clone args = %v", args)
}
}
func TestBuildPlanFailsWhenNoPortIsAvailable(t *testing.T) {
_, err := BuildPlan(Options{Tag: "dev", FindPort: func(int) int { return 0 }})
if err == nil {
t.Fatal("expected no-free-port error")
}
}
func TestStartPRIntegration(t *testing.T) {
if os.Getenv("HOMARR_DOCKER_INTEGRATION_TEST") != "1" {
t.Skip("set HOMARR_DOCKER_INTEGRATION_TEST=1 and HOMARR_TEST_PR=<number>")
}
pr, err := strconv.Atoi(os.Getenv("HOMARR_TEST_PR"))
if err != nil || pr <= 0 {
t.Fatal("HOMARR_TEST_PR must be a positive PR number")
}
plan, err := BuildPlan(Options{PR: pr})
if err != nil {
t.Fatal(err)
}
plan.Name += "_integration"
plan.Volume += "_integration"
defer docker.Remove(plan.Name)
if err := StartDetached(plan); err != nil {
t.Fatal(err)
}
if !docker.IsRunning(plan.Name) {
t.Fatalf("container %s did not remain running", plan.Name)
}
}