Adds test files for 6 source files that had no corresponding test:
bufpool_test.go (mining + node), metrics_test.go, version_test.go,
supervisor_test.go, mining_profile_test.go. Each follows
TestFilename_Function_{Good,Bad,Ugly} convention.
Also fixes 2 pre-existing compilation errors:
- ratelimiter_test.go: rl -> rateLimiter (leftover from AX rename)
- worker_test.go: worker.node -> worker.nodeManager (field was renamed)
Co-Authored-By: Charon <charon@lethean.io>
40 lines
1 KiB
Go
40 lines
1 KiB
Go
package mining
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestMiningProfile_RawConfig_MarshalJSON_Good(t *testing.T) {
|
|
raw := RawConfig([]byte(`{"pool":"pool.lthn.io:3333"}`))
|
|
data, err := raw.MarshalJSON()
|
|
if err != nil {
|
|
t.Fatalf("expected nil error, got %v", err)
|
|
}
|
|
if string(data) != `{"pool":"pool.lthn.io:3333"}` {
|
|
t.Fatalf("unexpected marshal result: %s", string(data))
|
|
}
|
|
}
|
|
|
|
func TestMiningProfile_RawConfig_MarshalJSON_Bad(t *testing.T) {
|
|
// nil RawConfig should marshal to "null"
|
|
var raw RawConfig
|
|
data, err := raw.MarshalJSON()
|
|
if err != nil {
|
|
t.Fatalf("expected nil error, got %v", err)
|
|
}
|
|
if string(data) != "null" {
|
|
t.Fatalf("expected \"null\", got %q", string(data))
|
|
}
|
|
}
|
|
|
|
func TestMiningProfile_RawConfig_MarshalJSON_Ugly(t *testing.T) {
|
|
// UnmarshalJSON on a non-nil pointer
|
|
raw := RawConfig([]byte(`{}`))
|
|
err := raw.UnmarshalJSON([]byte(`{"new":"data"}`))
|
|
if err != nil {
|
|
t.Fatalf("expected nil error, got %v", err)
|
|
}
|
|
if string(raw) != `{"new":"data"}` {
|
|
t.Fatalf("unexpected unmarshal result: %s", string(raw))
|
|
}
|
|
}
|