Refine vm ports output
Make banger vm ports single-target and collapse the old VM/WEB table shape into a simpler PROTO ENDPOINT PROCESS COMMAND view. Web listeners now surface directly as http or https, with clickable endpoints in the main endpoint column instead of a separate URL field. Classify TCP listeners with HTTPS-first probing so TLS services are not mislabeled as plain HTTP just because they answer bad cleartext requests with an HTTP error, then dedupe rows by rendered PROTO+ENDPOINT so dual-stack binds like 0.0.0.0 and :: only show once. Update the CLI/daemon regressions and README to match the new contract. Verified with GOCACHE=/tmp/banger-gocache go test ./..., make build, git diff --check, and ./banger vm ports --help.
This commit is contained in:
parent
5ad3b505dd
commit
3096de0a7f
6 changed files with 179 additions and 151 deletions
|
|
@ -162,6 +162,15 @@ func TestVMPortsCommandExists(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestVMPortsCommandRejectsMultipleRefs(t *testing.T) {
|
||||
cmd := NewBangerCommand()
|
||||
cmd.SetArgs([]string{"vm", "ports", "alpha", "beta"})
|
||||
err := cmd.Execute()
|
||||
if err == nil || !strings.Contains(err.Error(), "usage: banger vm ports <id-or-name>") {
|
||||
t.Fatalf("Execute() error = %v, want single-vm usage error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVMSetParamsFromFlags(t *testing.T) {
|
||||
params, err := vmSetParamsFromFlags("devbox", 4, 2048, "16G", true, false)
|
||||
if err != nil {
|
||||
|
|
@ -279,56 +288,43 @@ func TestAbsolutizeImageRegisterPaths(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPrintVMPortsTableSortsAndRendersURLs(t *testing.T) {
|
||||
results := []vmPortsBatchResult{
|
||||
{
|
||||
Target: resolvedVMTarget{Ref: "beta"},
|
||||
Result: api.VMPortsResult{
|
||||
Name: "beta",
|
||||
Ports: []api.VMPort{{
|
||||
Proto: "tcp",
|
||||
Port: 8080,
|
||||
Endpoint: "beta.vm:8080",
|
||||
Process: "python3",
|
||||
Command: "python3 -m http.server 8080",
|
||||
WebURL: "http://beta.vm:8080/",
|
||||
}},
|
||||
func TestPrintVMPortsTableSortsAndRendersURLEndpoints(t *testing.T) {
|
||||
result := api.VMPortsResult{
|
||||
Name: "alpha",
|
||||
Ports: []api.VMPort{
|
||||
{
|
||||
Proto: "https",
|
||||
Port: 443,
|
||||
Endpoint: "https://alpha.vm:443/",
|
||||
Process: "caddy",
|
||||
Command: "caddy run",
|
||||
},
|
||||
},
|
||||
{
|
||||
Target: resolvedVMTarget{Ref: "alpha"},
|
||||
Result: api.VMPortsResult{
|
||||
Name: "alpha",
|
||||
Ports: []api.VMPort{{
|
||||
Proto: "udp",
|
||||
Port: 53,
|
||||
Endpoint: "alpha.vm:53",
|
||||
Process: "dnsd",
|
||||
Command: "dnsd --foreground",
|
||||
}},
|
||||
{
|
||||
Proto: "udp",
|
||||
Port: 53,
|
||||
Endpoint: "alpha.vm:53",
|
||||
Process: "dnsd",
|
||||
Command: "dnsd --foreground",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
if err := printVMPortsTable(&out, results); err != nil {
|
||||
if err := printVMPortsTable(&out, result); err != nil {
|
||||
t.Fatalf("printVMPortsTable: %v", err)
|
||||
}
|
||||
lines := strings.Split(strings.TrimSpace(out.String()), "\n")
|
||||
if len(lines) != 3 {
|
||||
t.Fatalf("lines = %q, want header + 2 rows", lines)
|
||||
}
|
||||
if !strings.Contains(lines[0], "VM") || !strings.Contains(lines[0], "WEB") {
|
||||
t.Fatalf("header = %q, want VM/WEB columns", lines[0])
|
||||
if !strings.Contains(lines[0], "PROTO") || !strings.Contains(lines[0], "ENDPOINT") || strings.Contains(lines[0], "VM") || strings.Contains(lines[0], "WEB") {
|
||||
t.Fatalf("header = %q, want PROTO/ENDPOINT without VM/WEB", lines[0])
|
||||
}
|
||||
if !strings.Contains(lines[1], "alpha") || !strings.Contains(lines[1], "alpha.vm:53") || !strings.Contains(lines[1], "\t-\n") {
|
||||
// tabwriter output is space-expanded, so just require the dash placeholder.
|
||||
if !strings.Contains(lines[1], "alpha") || !strings.Contains(lines[1], "alpha.vm:53") || !strings.HasSuffix(strings.TrimSpace(lines[1]), "-") {
|
||||
t.Fatalf("first row = %q, want alpha row with dash web column", lines[1])
|
||||
}
|
||||
if !strings.Contains(lines[1], "https") || !strings.Contains(lines[1], "https://alpha.vm:443/") {
|
||||
t.Fatalf("first row = %q, want https endpoint row", lines[1])
|
||||
}
|
||||
if !strings.Contains(lines[2], "beta") || !strings.Contains(lines[2], "http://beta.vm:8080/") {
|
||||
t.Fatalf("second row = %q, want beta web url", lines[2])
|
||||
if !strings.Contains(lines[2], "udp") || !strings.Contains(lines[2], "alpha.vm:53") {
|
||||
t.Fatalf("second row = %q, want udp endpoint row", lines[2])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue