mirror of
https://github.com/go-i2p/go-sam-go.git
synced 2025-07-17 02:14:49 -04:00
Fix dupe config issues
This commit is contained in:
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user