//go:build cgo package main import ( "fmt" "os" "os/exec" "strings" "sync" "testing" ) // bdGraph runs "bd graph" with the given args and returns raw stdout. func bdGraph(t *testing.T, bd, dir string, args ...string) string { t.Helper() fullArgs := append([]string{"graph"}, args...) cmd := exec.Command(bd, fullArgs...) cmd.Dir = dir cmd.Env = bdEnv(dir) out, err := cmd.CombinedOutput() if err != nil { t.Fatalf("bd graph %s failed: %v\n%s", strings.Join(args, " "), err, out) } return string(out) } func TestEmbeddedGraph(t *testing.T) { if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" { t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests") } t.Parallel() bd := buildEmbeddedBD(t) dir, _, _ := bdInit(t, bd, "--prefix", "gr") // Create an epic with dependencies for graph testing. epic := bdCreate(t, bd, dir, "Graph epic", "--type", "epic") taskA := bdCreate(t, bd, dir, "Graph task A", "--type", "task") taskB := bdCreate(t, bd, dir, "Graph task B", "--type", "task") taskC := bdCreate(t, bd, dir, "Graph task C", "--type", "task") bdDep(t, bd, dir, "add", taskA.ID, epic.ID, "--type", "parent-child") bdDep(t, bd, dir, "add", taskB.ID, epic.ID, "--type", "parent-child") bdDep(t, bd, dir, "add", taskC.ID, taskA.ID) // C depends on A standalone := bdCreate(t, bd, dir, "Standalone issue", "--type", "task") // ===== Single issue graph ===== t.Run("single_issue", func(t *testing.T) { out := bdGraph(t, bd, dir, epic.ID) if !strings.Contains(out, epic.ID) { t.Errorf("expected epic ID in graph: %s", out) } }) // ===== --all ===== t.Run("all_issues", func(t *testing.T) { out := bdGraph(t, bd, dir, "--all") if !strings.Contains(out, epic.ID) { t.Errorf("expected epic in --all graph: %s", out) } }) // ===== --compact ===== t.Run("compact_format", func(t *testing.T) { out := bdGraph(t, bd, dir, "--compact", epic.ID) if len(out) == 0 { t.Error("expected non-empty compact output") } }) // ===== --box ===== t.Run("box_format", func(t *testing.T) { out := bdGraph(t, bd, dir, "--box", epic.ID) if len(out) == 0 { t.Error("expected non-empty box output") } }) // ===== --dot ===== t.Run("dot_format", func(t *testing.T) { out := bdGraph(t, bd, dir, "--dot", epic.ID) if !strings.Contains(out, "digraph") { t.Errorf("expected 'digraph' in DOT output: %s", out) } }) // ===== --html ===== t.Run("html_format", func(t *testing.T) { out := bdGraph(t, bd, dir, "--html", epic.ID) if !strings.Contains(out, "