package validation import ( "context" "strings" "testing" "gitea.maximumdirect.net/eric/ReleaseKit/internal/git" ) func TestCheckWorkspaceFilesReportsCommittedBlobNames(t *testing.T) { entries := []git.TreeEntry{ {Path: "go.work", Type: "blob", Mode: "100644"}, {Path: "nested/go.work.sum", Type: "blob", Mode: "100644"}, {Path: "vendor/nested/link/go.work", Type: "blob", Mode: "120000"}, {Path: "nested/not-go.work.backup", Type: "blob", Mode: "100644"}, {Path: "submodule/go.work", Type: "commit", Mode: "160000"}, } tree := &CandidateTree{entries: entries, inputEntries: entries} err := checkWorkspaceFiles(tree) failure, ok := err.(*Failure) if !ok || failure.Check != WorkspaceFiles { t.Fatalf("checkWorkspaceFiles error = %v, want workspace-files failure", err) } want := map[string]bool{ "go.work": false, "nested/go.work.sum": false, "vendor/nested/link/go.work": false, } if len(failure.Findings) != len(want) { t.Fatalf("workspace findings = %#v, want %d paths", failure.Findings, len(want)) } for _, finding := range failure.Findings { if _, ok := want[finding.Path]; !ok { t.Errorf("unexpected workspace path %q", finding.Path) } want[finding.Path] = true } for path, found := range want { if !found { t.Errorf("workspace path %q was not reported", path) } } } func TestCheckWorkspaceFilesAllowsOtherNames(t *testing.T) { entries := []git.TreeEntry{ {Path: "go.mod", Type: "blob", Mode: "100644"}, {Path: "examples/go.work.example", Type: "blob", Mode: "100644"}, } tree := &CandidateTree{entries: entries, inputEntries: entries} if err := checkWorkspaceFiles(tree); err != nil { t.Fatalf("checkWorkspaceFiles error = %v, want no findings", err) } } func TestRunWorkspaceFilesUsesCommittedTreeWithGoWorkspaceDisabled(t *testing.T) { t.Setenv("GOWORK", "off") repository := newTreeRepository(t) writeTreeFile(t, repository, "go.work", []byte("go 1.25.0\n")) writeTreeFile(t, repository, "nested/go.work.sum", []byte("committed workspace metadata\n")) gitTree(t, repository, "add", ".") gitTree(t, repository, "commit", "-m", "capture workspace files") commit := strings.TrimSpace(gitTree(t, repository, "rev-parse", "HEAD")) writeTreeFile(t, repository, "untracked/go.work.sum", []byte("uncommitted workspace metadata\n")) logPath := installGoShim(t, "", false) if err := Run(context.Background(), Request{RepositoryDir: repository, Commit: commit}); err != nil { t.Fatalf("default validation = %v, want workspace check disabled", err) } logPath = installGoShim(t, "", false) err := Run(context.Background(), Request{ RepositoryDir: repository, Commit: commit, Settings: Settings{ModuleDistribution: ModuleDistributionSettings{ WorkspaceFiles: true, }}, }) failure, ok := err.(*Failure) if !ok || failure.Check != WorkspaceFiles { t.Fatalf("selected workspace error = %v, want workspace-files failure", err) } want := map[string]bool{"go.work": false, "nested/go.work.sum": false} if len(failure.Findings) != len(want) { t.Fatalf("workspace findings = %#v, want committed paths only", failure.Findings) } for _, finding := range failure.Findings { if _, ok := want[finding.Path]; !ok { t.Errorf("unexpected workspace path %q", finding.Path) } want[finding.Path] = true } for path, found := range want { if !found { t.Errorf("committed workspace path %q was not reported", path) } } if got := strings.Join(readGoShimLog(t, logPath), "\n"); !strings.Contains(got, "test -mod=readonly -count=1 ./...") { t.Fatalf("Go commands = %q, want ordinary test suite with GOWORK=off", got) } }