Fix dupe config issues

This commit is contained in:
eyedeekay
2025-05-27 20:22:20 -04:00
parent 21e42bf030
commit 7febf2dd07
2 changed files with 47 additions and 3 deletions

View File

@ -311,16 +311,24 @@ func (f *I2PConfig) DoZero() string {
// formatConfigPair creates a configuration string for inbound/outbound pairs
func (f *I2PConfig) formatConfigPair(direction, property string, value interface{}) string {
var valueStr string
switch v := value.(type) {
case int:
return fmt.Sprintf("%s.%s=%d", direction, property, v)
if v == 0 {
return "" // Skip zero values to avoid duplicates
}
valueStr = strconv.Itoa(v)
case string:
return fmt.Sprintf("%s.%s=%s", direction, property, v)
if v == "" {
return ""
}
valueStr = v
case bool:
return fmt.Sprintf("%s.%s=%t", direction, property, v)
valueStr = strconv.FormatBool(v)
default:
return ""
}
return fmt.Sprintf("%s.%s=%s", direction, property, valueStr)
}
func (f *I2PConfig) InboundLength() string {

View File

@ -1,6 +1,7 @@
package common
import (
"strings"
"testing"
)
@ -158,3 +159,38 @@ func TestLeaseSetSettings_Formatting(t *testing.T) {
})
}
}
func TestTunnelConfigNoDuplicates(t *testing.T) {
cfg := &I2PConfig{
InLength: 3,
OutLength: 3,
InQuantity: 2,
OutQuantity: 2,
}
config := cfg.TunnelConfig()
params := strings.Split(config, " ")
// Verify no duplicate parameters
seen := make(map[string]bool)
for _, param := range params {
if seen[param] {
t.Errorf("Duplicate parameter found: %s", param)
}
seen[param] = true
}
// Verify expected parameters present
expectedParams := []string{
"inbound.length=3",
"outbound.length=3",
"inbound.quantity=2",
"outbound.quantity=2",
}
for _, expected := range expectedParams {
if !strings.Contains(config, expected) {
t.Errorf("Missing expected parameter: %s", expected)
}
}
}