mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-12-12 23:18:49 +00:00
- Added comprehensive tests for production command flag parsing to ensure correct handling of bootstrap, VPS IP, and peer configurations. - Updated production command help output to clarify the usage of new flags, including `--vps-ip` and `--bootstrap-join`. - Modified the configuration generation logic to incorporate the new `bootstrapJoin` parameter for secondary bootstrap nodes. - Enhanced systemd service generation to include the correct advertise IP and join address for non-bootstrap nodes. - Implemented tests for RQLite service generation to verify the inclusion of join addresses and advertise IPs in the generated units.
89 lines
2.3 KiB
Go
89 lines
2.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// TestProdCommandFlagParsing verifies that prod command flags are parsed correctly
|
|
func TestProdCommandFlagParsing(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
args []string
|
|
expectBootstrap bool
|
|
expectVPSIP string
|
|
expectBootstrapJoin string
|
|
expectPeers string
|
|
}{
|
|
{
|
|
name: "bootstrap node",
|
|
args: []string{"install", "--bootstrap"},
|
|
expectBootstrap: true,
|
|
},
|
|
{
|
|
name: "non-bootstrap with vps-ip",
|
|
args: []string{"install", "--vps-ip", "10.0.0.2", "--peers", "multiaddr1,multiaddr2"},
|
|
expectVPSIP: "10.0.0.2",
|
|
expectPeers: "multiaddr1,multiaddr2",
|
|
},
|
|
{
|
|
name: "secondary bootstrap",
|
|
args: []string{"install", "--bootstrap", "--vps-ip", "10.0.0.3", "--bootstrap-join", "10.0.0.1:7001"},
|
|
expectBootstrap: true,
|
|
expectVPSIP: "10.0.0.3",
|
|
expectBootstrapJoin: "10.0.0.1:7001",
|
|
},
|
|
{
|
|
name: "with domain",
|
|
args: []string{"install", "--bootstrap", "--domain", "example.com"},
|
|
expectBootstrap: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
// Extract flags manually to verify parsing logic
|
|
force := false
|
|
isBootstrap := false
|
|
var vpsIP, domain, peersStr, bootstrapJoin string
|
|
|
|
for i, arg := range tt.args {
|
|
switch arg {
|
|
case "--force":
|
|
force = true
|
|
case "--bootstrap":
|
|
isBootstrap = true
|
|
case "--peers":
|
|
if i+1 < len(tt.args) {
|
|
peersStr = tt.args[i+1]
|
|
}
|
|
case "--vps-ip":
|
|
if i+1 < len(tt.args) {
|
|
vpsIP = tt.args[i+1]
|
|
}
|
|
case "--domain":
|
|
if i+1 < len(tt.args) {
|
|
domain = tt.args[i+1]
|
|
}
|
|
case "--bootstrap-join":
|
|
if i+1 < len(tt.args) {
|
|
bootstrapJoin = tt.args[i+1]
|
|
}
|
|
}
|
|
}
|
|
|
|
if isBootstrap != tt.expectBootstrap {
|
|
t.Errorf("expected bootstrap=%v, got %v", tt.expectBootstrap, isBootstrap)
|
|
}
|
|
if vpsIP != tt.expectVPSIP {
|
|
t.Errorf("expected vpsIP=%q, got %q", tt.expectVPSIP, vpsIP)
|
|
}
|
|
if peersStr != tt.expectPeers {
|
|
t.Errorf("expected peers=%q, got %q", tt.expectPeers, peersStr)
|
|
}
|
|
if bootstrapJoin != tt.expectBootstrapJoin {
|
|
t.Errorf("expected bootstrapJoin=%q, got %q", tt.expectBootstrapJoin, bootstrapJoin)
|
|
}
|
|
})
|
|
}
|
|
}
|