Mining/pkg/node/lethean_test.go
Claude 6555e1211c
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
ax(node): add missing Bad and Ugly test triads for parseComment
AX principle 10 requires all three categories (Good, Bad, Ugly) per
function. lethean_test.go had only Good for parseComment; Bad (invalid
input, missing keys, empty values) and Ugly (empty string, semicolons
only, duplicate keys, value-with-equals) are now present.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 08:12:03 +01:00

85 lines
2 KiB
Go

// Copyright (c) 2017-2026 Lethean (https://lt.hn)
// SPDX-License-Identifier: EUPL-1.2
package node
import (
"testing"
)
func TestParseComment_Good(t *testing.T) {
tests := []struct {
input string
key string
want string
}{
{"v=lthn1;type=gateway;cap=vpn,dns", "type", "gateway"},
{"v=lthn1;cap=pool", "cap", "pool"},
{"v=lthn1", "v", "lthn1"},
}
for _, tt := range tests {
result := parseComment(tt.input)
if result[tt.key] != tt.want {
t.Errorf("parseComment(%q)[%q] = %q, want %q", tt.input, tt.key, result[tt.key], tt.want)
}
}
}
func TestParseComment_Bad(t *testing.T) {
tests := []struct {
input string
key string
want string
}{
{"noequals", "noequals", ""},
{"k=v", "missing", ""},
{"=v", "", ""},
}
for _, tt := range tests {
result := parseComment(tt.input)
if result[tt.key] != tt.want {
t.Errorf("parseComment(%q)[%q] = %q, want %q", tt.input, tt.key, result[tt.key], tt.want)
}
}
}
func TestParseComment_Ugly(t *testing.T) {
tests := []struct {
name string
input string
key string
want string
}{
{"empty string", "", "k", ""},
{"semicolons only", ";;;", "k", ""},
{"duplicate keys last wins", "k=first;k=second", "k", "second"},
{"value with equals", "k=v=extra", "k", "v=extra"},
}
for _, tt := range tests {
result := parseComment(tt.input)
if result[tt.key] != tt.want {
t.Errorf("%s: parseComment(%q)[%q] = %q, want %q", tt.name, tt.input, tt.key, result[tt.key], tt.want)
}
}
}
func TestGetChainInfo_Bad_WrongURL(t *testing.T) {
_, err := GetChainInfo("http://127.0.0.1:19999")
if err == nil {
t.Error("expected error for unreachable daemon")
}
}
func TestDiscoverPools_Bad_WrongURL(t *testing.T) {
pools := DiscoverPools("http://127.0.0.1:19999")
if len(pools) != 0 {
t.Errorf("expected 0 pools for unreachable daemon, got %d", len(pools))
}
}
func TestDiscoverGateways_Bad_WrongURL(t *testing.T) {
gateways := DiscoverGateways("http://127.0.0.1:19999")
if len(gateways) != 0 {
t.Errorf("expected 0 gateways for unreachable daemon, got %d", len(gateways))
}
}