Mining/pkg/node/lethean_test.go
Claude acef50ad62
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
ax(node): rename tt loop variable to testCase in lethean_test.go
AX Principle #1 — predictable names over short names. The `tt` loop variable
is a two-letter abbreviation with no defined exception in the AX naming rules
(only `i`, `_`, `t`, `c` are acceptable short names). Renamed to `testCase`
throughout TestParseComment_{Good,Bad,Ugly}.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 16:36:41 +01:00

85 lines
2.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 _, testCase := range tests {
result := parseComment(testCase.input)
if result[testCase.key] != testCase.want {
t.Errorf("parseComment(%q)[%q] = %q, want %q", testCase.input, testCase.key, result[testCase.key], testCase.want)
}
}
}
func TestParseComment_Bad(t *testing.T) {
tests := []struct {
input string
key string
want string
}{
{"noequals", "noequals", ""},
{"k=v", "missing", ""},
{"=v", "", ""},
}
for _, testCase := range tests {
result := parseComment(testCase.input)
if result[testCase.key] != testCase.want {
t.Errorf("parseComment(%q)[%q] = %q, want %q", testCase.input, testCase.key, result[testCase.key], testCase.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 _, testCase := range tests {
result := parseComment(testCase.input)
if result[testCase.key] != testCase.want {
t.Errorf("%s: parseComment(%q)[%q] = %q, want %q", testCase.name, testCase.input, testCase.key, result[testCase.key], testCase.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))
}
}