package deps

import "testing"

func TestCleanupStaleDevProcessesSweepsRepo(t *testing.T) {
	old := sweepRepoProcesses
	t.Cleanup(func() { sweepRepoProcesses = old })

	var got string
	sweepRepoProcesses = func(repoRoot string) {
		got = repoRoot
	}

	cleanupStaleDevProcesses("/repo")
	if got != "/repo" {
		t.Fatalf("swept repo %q, want /repo", got)
	}
}

func TestCleanupStaleDevProcessesSweepsStalePlaygrounds(t *testing.T) {
	oldSweepRepo := sweepRepoProcesses
	oldSweepTiDB := sweepStalePlaygrounds
	t.Cleanup(func() {
		sweepRepoProcesses = oldSweepRepo
		sweepStalePlaygrounds = oldSweepTiDB
	})

	sweepRepoProcesses = func(string) {}
	var tidbRepo string
	sweepStalePlaygrounds = func(repoRoot string) {
		tidbRepo = repoRoot
	}

	cleanupStaleDevProcesses("/repo")
	if tidbRepo != "/repo" {
		t.Fatalf("TiDB sweep received repo %q, want /repo", tidbRepo)
	}
}
