Carry module identity through candidate results
This commit is contained in:
@@ -71,7 +71,7 @@ func TestCheckCapturesCandidateAndCallsAdditionalChecksOnce(t *testing.T) {
|
||||
if seen != candidate {
|
||||
t.Fatalf("callback candidate = %#v, returned candidate = %#v", seen, candidate)
|
||||
}
|
||||
if candidate.RepositoryDir != repository || candidate.Commit != commit || candidate.Version != testVersion {
|
||||
if candidate.RepositoryDir != repository || candidate.ModuleDir != repository || candidate.ModulePath != "example.com/candidate" || candidate.Tag != testVersion || candidate.Commit != commit || candidate.Version != testVersion {
|
||||
t.Fatalf("Check() candidate = %#v", candidate)
|
||||
}
|
||||
if tags := gitOutputForTest(t, repository, "tag", "--list"); tags != "" {
|
||||
@@ -82,6 +82,67 @@ func TestCheckCapturesCandidateAndCallsAdditionalChecksOnce(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCaptureUsesNestedMajorModuleNoteAndTag(t *testing.T) {
|
||||
repository := newRepository(t, "# Example Product v1.2.3\n\nRoot release.\n")
|
||||
moduleDir := "integrations/ckconfig/v2"
|
||||
writeTestFile(t, repository, moduleDir+"/go.mod", "module example.com/ckconfig/v2\n\ngo 1.25.0\n")
|
||||
writeTestFile(t, repository, moduleDir+"/docs/releases/v2.3.4.md", "# Example Product v2.3.4\n\nNested release.\n")
|
||||
gitRun(t, repository, "add", moduleDir)
|
||||
gitRun(t, repository, "commit", "-m", "add nested major module")
|
||||
|
||||
captured, err := Capture(context.Background(), Request{
|
||||
RepositoryDir: repository,
|
||||
ModuleDir: moduleDir,
|
||||
Product: "Example Product",
|
||||
Version: "v2.3.4",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if captured.RepositoryDir != repository || captured.ModuleDir != filepath.Join(repository, moduleDir) || captured.ModulePath != "example.com/ckconfig/v2" || captured.Tag != "integrations/ckconfig/v2.3.4" {
|
||||
t.Fatalf("nested candidate identity = %#v", captured)
|
||||
}
|
||||
if !strings.Contains(captured.Note, "Nested release.") || strings.Contains(captured.Note, "Root release.") {
|
||||
t.Fatalf("captured note = %q, want nested module note", captured.Note)
|
||||
}
|
||||
|
||||
gitRun(t, repository, "tag", captured.Tag)
|
||||
conflicted, err := Capture(context.Background(), Request{
|
||||
RepositoryDir: repository,
|
||||
ModuleDir: moduleDir,
|
||||
Product: "Example Product",
|
||||
Version: "v2.3.4",
|
||||
})
|
||||
if err == nil || !strings.Contains(err.Error(), captured.Tag) {
|
||||
t.Fatalf("Capture() with existing nested tag returned %#v, %v", conflicted, err)
|
||||
}
|
||||
if conflicted.ModulePath != captured.ModulePath || conflicted.Tag != captured.Tag || conflicted.Commit != captured.Commit {
|
||||
t.Fatalf("capture failure lost identity evidence: %#v", conflicted)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCaptureKeepsRepositoryWideCleanlinessGuardForNestedSelection(t *testing.T) {
|
||||
repository := newRepository(t, "# Example Product v1.2.3\n")
|
||||
moduleDir := "integrations/ckconfig"
|
||||
writeTestFile(t, repository, moduleDir+"/go.mod", "module example.com/ckconfig\n")
|
||||
writeTestFile(t, repository, moduleDir+"/docs/releases/"+testVersion+".md", "# Example Product v1.2.3\n")
|
||||
gitRun(t, repository, "add", moduleDir)
|
||||
gitRun(t, repository, "commit", "-m", "add nested module")
|
||||
writeTestFile(t, repository, "sibling/untracked.txt", "dirty\n")
|
||||
captured, err := Capture(context.Background(), Request{
|
||||
RepositoryDir: repository,
|
||||
ModuleDir: moduleDir,
|
||||
Product: "Example Product",
|
||||
Version: testVersion,
|
||||
})
|
||||
if err == nil || !strings.Contains(err.Error(), "must be clean") {
|
||||
t.Fatalf("Capture() = %#v, %v; want repository-wide dirty-state rejection", captured, err)
|
||||
}
|
||||
if captured.Commit == "" {
|
||||
t.Fatalf("dirty-state error lost captured commit: %#v", captured)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckStopsBeforeProductAndBuildCallbacksWhenGoFormatFails(t *testing.T) {
|
||||
repository := newRepository(t, "# Example Product v1.2.3\n\nRelease note.\n")
|
||||
writeTestFile(t, repository, "unformatted.go", "package candidate\nfunc Value( ) int{return 1}\n")
|
||||
@@ -423,7 +484,7 @@ func TestCheckRechecksHeadAndWorktreeAfterCallback(t *testing.T) {
|
||||
|
||||
func TestCheckRechecksLocalTagAfterCallback(t *testing.T) {
|
||||
repository := newRepository(t, "# Example Product v1.2.3\n")
|
||||
_, err := Check(context.Background(), Request{
|
||||
captured, err := Check(context.Background(), Request{
|
||||
RepositoryDir: repository,
|
||||
Product: "Example Product",
|
||||
Version: testVersion,
|
||||
@@ -435,6 +496,9 @@ func TestCheckRechecksLocalTagAfterCallback(t *testing.T) {
|
||||
if err == nil || !strings.Contains(err.Error(), "appeared during validation") {
|
||||
t.Fatalf("Check() error = %v, want tag recheck error", err)
|
||||
}
|
||||
if captured.RepositoryDir != repository || captured.ModuleDir != repository || captured.ModulePath != "example.com/candidate" || captured.Tag != testVersion || captured.Commit == "" {
|
||||
t.Fatalf("tag recheck failure lost candidate evidence: %#v", captured)
|
||||
}
|
||||
}
|
||||
|
||||
func validRequest(repository string) Request {
|
||||
|
||||
Reference in New Issue
Block a user