You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by li...@apache.org on 2026/10/12 07:26:06 UTC

(rocketmq-dashboard) branch rocketmq-studio updated: test(rmqctl): give the packaging gate a completion fixture (#6330)

This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/rocketmq-studio by this push:
     new d409efd1f test(rmqctl): give the packaging gate a completion fixture (#6330)
d409efd1f is described below

commit d409efd1fb923176240c6f9be60b0ce8320674a0
Author: lizhimins <70...@qq.com>
AuthorDate: Mon Oct 12 15:26:01 2026 +0800

    test(rmqctl): give the packaging gate a completion fixture (#6330)
    
    Follow-up to #5883, which made package-release.sh fail closed when the completion scripts are absent: the packaging test still called it without COMPLETION_DIR, so a clean checkout turned the gate (and the rmqctl-test CI job, which runs before make build) red for a reason unrelated to the change under test.
    
    - Supply a fixture holding the four scripts `make completion` produces and pass it as COMPLETION_DIR.
    - Assert all four reach the archive, so dropping the copy step fails the test.
    - Add the missing-directory case and require the guard's own diagnostic: with the guard removed the cp below it still fails, so the exit status alone does not pin it.
    
    Both mutations verified red with `go test -count=1 ./scripts/...` (a plain run is cached and does not notice a changed shell script); the unmutated tree is green on linux and windows.
---
 rmqctl/scripts/license-binary_test.go | 36 +++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/rmqctl/scripts/license-binary_test.go b/rmqctl/scripts/license-binary_test.go
index f56a6e0e5..6193f78c6 100644
--- a/rmqctl/scripts/license-binary_test.go
+++ b/rmqctl/scripts/license-binary_test.go
@@ -48,17 +48,35 @@ func TestBinaryLicensePackagingTest(t *testing.T) {
 			if output, err := generate.CombinedOutput(); err != nil {
 				t.Fatalf("license generation failed: %v\n%s", err, output)
 			}
-			pack := func(osName, material string, success bool) {
+			// package-release.sh fails closed when the completion scripts are absent, so the
+			// fixture has to supply them; `make completion` is what produces the real four.
+			completion := filepath.Join(dir, "completion")
+			completionScripts := []string{"rmqctl.bash", "_rmqctl", "rmqctl.fish", "rmqctl.ps1"}
+			if err := os.MkdirAll(completion, 0755); err != nil {
+				t.Fatal(err)
+			}
+			for _, name := range completionScripts {
+				if err := os.WriteFile(filepath.Join(completion, name), []byte("# "+name+" fixture\n"), 0644); err != nil {
+					t.Fatal(err)
+				}
+			}
+			pack := func(osName, material, completionDir, wantOutput string, success bool) {
 				t.Helper()
 				cmd := exec.Command("bash", filepath.Join(root, "rmqctl/scripts/package-release.sh"),
 					binary, osName, "amd64", "fixture", material, filepath.Join(dir, "packages"))
-				cmd.Env = append(os.Environ(), "GO="+goCommand)
+				cmd.Env = append(os.Environ(), "GO="+goCommand, "COMPLETION_DIR="+completionDir)
 				output, err := cmd.CombinedOutput()
 				if (err == nil) != success {
 					t.Fatalf("packaging gate returned the wrong result success=%v err=%v\n%s", success, err, output)
 				}
+				// A missing completion directory has to fail with the guard's own diagnostic: dropping
+				// the guard still exits non-zero (the cp below it fails), so the status alone does not
+				// pin it and the operator would be left with a cryptic cp error instead.
+				if wantOutput != "" && !strings.Contains(string(output), wantOutput) {
+					t.Fatalf("packaging gate did not report %q:\n%s", wantOutput, output)
+				}
 			}
-			pack(target, legal, true)
+			pack(target, legal, completion, "", true)
 			contents := map[string]string{}
 			archive := filepath.Join(dir, "packages", "rmqctl-"+target+"-amd64-fixture")
 			if target == "windows" {
@@ -118,12 +136,18 @@ func TestBinaryLicensePackagingTest(t *testing.T) {
 			if target == "windows" && !strings.Contains(contents["LICENSE"], "mousetrap") {
 				t.Fatal("the Windows package is missing a platform-specific dependency license")
 			}
-			pack("darwin", legal, false)
-			pack(target, "", false)
+			for _, name := range completionScripts {
+				if !strings.Contains(contents["completion/"+name], name+" fixture") {
+					t.Fatalf("the package is missing completion/%s", name)
+				}
+			}
+			pack("darwin", legal, completion, "", false)
+			pack(target, "", completion, "", false)
+			pack(target, legal, filepath.Join(dir, "completion-not-generated"), "Missing completion scripts", false)
 			if err := os.WriteFile(filepath.Join(legal, "NOTICE"), []byte("tampered"), 0644); err != nil {
 				t.Fatal(err)
 			}
-			pack(target, legal, false)
+			pack(target, legal, completion, "", false)
 		})
 	}
 }