Mining/pkg/node/lethean_test.go
Claude 8a899153ed
Some checks failed
Security Scan / security (push) Successful in 34s
Test / test (push) Has been cancelled
ax(node): strip _WrongURL suffix from lethean test names
Test names must follow TestFilename_Function_{Good,Bad,Ugly}.
The extra _WrongURL qualifier broke the AX naming convention
(RFC-CORE-008 §10 — CLI tests as artifact validation).

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 12:23:44 +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(t *testing.T) {
_, err := GetChainInfo("http://127.0.0.1:19999")
if err == nil {
t.Error("expected error for unreachable daemon")
}
}
func TestDiscoverPools_Bad(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(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))
}
}