-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrelease_evidence_test.go
More file actions
69 lines (64 loc) · 1.96 KB
/
Copy pathrelease_evidence_test.go
File metadata and controls
69 lines (64 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
)
// TestSmokeReleaseEmitsEvidence runs the real smoke script against a fake
// production surface and asserts the evidence block it writes carries the
// release identity and smoke result. This proves the generator the workflow
// depends on keeps working end to end.
func TestSmokeReleaseEmitsEvidence(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("smoke script is bash; not run on the Windows job")
}
for _, bin := range []string{"bash", "curl", "grep"} {
if _, err := exec.LookPath(bin); err != nil {
t.Skipf("%s not available: %v", bin, err)
}
}
const asset = "assets/app-deadbeef.js"
mux := http.NewServeMux()
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) })
mux.HandleFunc("/api/debug/health", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) })
mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
_, _ = fmt.Fprintf(w, `<!doctype html><html><head><script src="%s"></script></head><body></body></html>`, asset)
})
srv := httptest.NewServer(mux)
defer srv.Close()
out := filepath.Join(t.TempDir(), "evidence.md")
cmd := exec.Command("bash", "tools/smoke/release.sh")
cmd.Env = append(os.Environ(),
"BASE_URL="+srv.URL,
"TAG=v9.9.9-test",
"COMMIT=abcdef0",
"BUILD_URL=https://build.example/run/1",
"DEPLOY_URL=https://deploy.example",
"OUTPUT_MD="+out,
)
if combined, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("smoke script failed: %v\n%s", err, combined)
}
body, err := os.ReadFile(out)
if err != nil {
t.Fatalf("evidence not written: %v", err)
}
evidence := string(body)
for _, want := range []string{
"<!-- release-evidence -->",
"v9.9.9-test",
"abcdef0",
asset,
"/healthz",
} {
if !strings.Contains(evidence, want) {
t.Errorf("evidence missing %q:\n%s", want, evidence)
}
}
}