Files
Pulse/cmd/pulse-sensor-proxy/ssh_parsing_test.go
courtmanr@gmail.com 1ae34285c5 fix(sensor-proxy): relax pvecm status parsing to support decimal node IDs
Fixes an issue where pvecm status output using decimal node IDs (e.g. '1' instead of '0x1') caused node discovery to fail. Added test case for this format.
2025-11-23 08:21:58 +00:00

86 lines
2.0 KiB
Go

package main
import (
"testing"
)
func TestParseClusterNodes(t *testing.T) {
tests := []struct {
name string
output string
want []string
wantErr bool
}{
{
name: "standard output",
output: `Membership information
----------------------
Nodeid Votes Name
0x00000001 1 192.168.1.10
0x00000002 1 192.168.1.11`,
want: []string{"192.168.1.10", "192.168.1.11"},
},
{
name: "output with QDevice flags",
output: `Membership information
----------------------
Nodeid Votes Name
0x00000001 1 A,V,NMW 192.168.1.10
0x00000002 1 A,V,NMW 192.168.1.11`,
want: []string{"192.168.1.10", "192.168.1.11"},
},
{
name: "output with local suffix",
output: `Membership information
----------------------
Nodeid Votes Name
0x00000001 1 192.168.1.10 (local)
0x00000002 1 192.168.1.11`,
want: []string{"192.168.1.10", "192.168.1.11"},
},
{
name: "mixed output",
output: `Membership information
----------------------
Nodeid Votes Name
0x00000001 1 A,V,NMW 192.168.1.10 (local)
0x00000002 1 192.168.1.11`,
want: []string{"192.168.1.10", "192.168.1.11"},
},
{
name: "no nodes",
output: "some random text",
wantErr: true,
},
{
name: "numeric node id format",
output: `Membership information
----------------------
Nodeid Votes Name
1 10.0.0.5 2`,
want: []string{"10.0.0.5"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseClusterNodes(tt.output)
if (err != nil) != tt.wantErr {
t.Errorf("parseClusterNodes() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr {
if len(got) != len(tt.want) {
t.Errorf("parseClusterNodes() got = %v, want %v", got, tt.want)
} else {
for i := range got {
if got[i] != tt.want[i] {
t.Errorf("parseClusterNodes() got[%d] = %v, want %v", i, got[i], tt.want[i])
}
}
}
}
})
}
}