mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-02-18 00:17:39 +01:00
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.
86 lines
2.0 KiB
Go
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])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|