Skip to content

Commit 9e909a2

Browse files
aledbfclaude
andcommitted
test(cli): say why the CA bundle e2e TLS server has no address
The server container ran with --rm and its address came from the bridge network by name, with docker inspect's stderr discarded: on CI the lookup failed with a bare "exit status 1". Keep the container until cleanup, read the address from whatever network it is on, and report the inspect output, the container's state and its logs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 156dd0e commit 9e909a2

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

‎internal/cli/e2e_ca_bundle_test.go‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,24 @@ func startTLSServer(t *testing.T, ca *testCA) (id, url string) {
3434
if err := os.Chmod(certs, 0o755); err != nil {
3535
t.Fatal(err)
3636
}
37-
out, err := exec.Command("docker", "run", "-d", "--rm", "-v", certs+":/certs:ro", e2eBaseImage, "sh", "-c",
37+
out, err := exec.Command("docker", "run", "-d", "-v", certs+":/certs:ro", e2eBaseImage, "sh", "-c",
3838
"while [ ! -f /certs/ready ]; do sleep 0.1; done; exec openssl s_server -quiet -www -accept 8443 -cert /certs/cert.pem -key /certs/key.pem").CombinedOutput()
3939
if err != nil {
4040
t.Fatalf("start TLS server: %v\n%s", err, out)
4141
}
4242
id = strings.TrimSpace(string(out))
4343
t.Cleanup(func() { removeByID(id) })
44-
ipOut, err := exec.Command("docker", "inspect", "-f", "{{.NetworkSettings.Networks.bridge.IPAddress}}", id).Output()
44+
ipOut, err := exec.Command("docker", "inspect", "-f", "{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}", id).CombinedOutput()
4545
if err != nil {
46-
t.Fatalf("server address: %v", err)
46+
t.Fatalf("server address: %v\n%s\n%s", err, ipOut, serverDiagnostics(id))
47+
}
48+
fields := strings.Fields(string(ipOut))
49+
var ip net.IP
50+
if len(fields) > 0 {
51+
ip = net.ParseIP(fields[0])
4752
}
48-
ip := net.ParseIP(strings.TrimSpace(string(ipOut)))
4953
if ip == nil {
50-
t.Fatalf("server address %q", ipOut)
54+
t.Fatalf("server address %q\n%s", ipOut, serverDiagnostics(id))
5155
}
5256
certPEM, keyPEM := ca.serverPEM(t, ip)
5357
writeTestFile(t, filepath.Join(certs, "cert.pem"), certPEM)
@@ -65,12 +69,18 @@ func startTLSServer(t *testing.T, ca *testCA) (id, url string) {
6569
return id, "https://" + addr + "/"
6670
}
6771
if time.Now().After(deadline) {
68-
t.Fatalf("TLS server at %s never answered: %v", addr, err)
72+
t.Fatalf("TLS server at %s never answered: %v\n%s", addr, err, serverDiagnostics(id))
6973
}
7074
time.Sleep(200 * time.Millisecond)
7175
}
7276
}
7377

78+
func serverDiagnostics(id string) string {
79+
state, _ := exec.Command("docker", "inspect", "-f", "{{json .State}} {{json .NetworkSettings.Networks}}", id).CombinedOutput()
80+
logs, _ := exec.Command("docker", "logs", id).CombinedOutput()
81+
return fmt.Sprintf("state: %s\nlogs: %s", state, logs)
82+
}
83+
7484
// imageLeaks lists the files of image's own layers among files, and where the
7585
// markers appear in what image adds to base: the content of its own layers'
7686
// files and its config, which holds

0 commit comments

Comments
 (0)