Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
102 lines
2.9 KiB
Go
102 lines
2.9 KiB
Go
//go:build !windows
|
|
|
|
package client
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestWGSetupJSONReturnsError verifies that the non-Windows stub returns a
|
|
// JSON error payload indicating WireGuard is not available on this platform.
|
|
func TestPathTracerStubWGSetupJSONReturnsError(t *testing.T) {
|
|
raw := WGSetupJSON()
|
|
if raw == "" {
|
|
t.Fatal("WGSetupJSON returned empty string")
|
|
}
|
|
|
|
var result WGSetupResult
|
|
if err := json.Unmarshal([]byte(raw), &result); err != nil {
|
|
t.Fatalf("WGSetupJSON returned invalid JSON: %v", err)
|
|
}
|
|
|
|
if result.Error == "" {
|
|
t.Error("WGSetupJSON stub must return a non-empty error field on non-Windows")
|
|
}
|
|
|
|
// Sanity-check: no real public key or port should be populated.
|
|
if result.PublicKey != "" {
|
|
t.Errorf("expected empty PublicKey in stub, got %q", result.PublicKey)
|
|
}
|
|
if result.ExternalPort != 0 {
|
|
t.Errorf("expected ExternalPort=0 in stub, got %d", result.ExternalPort)
|
|
}
|
|
}
|
|
|
|
// TestWGConfigureNoOp verifies that WGConfigure is a no-op on non-Windows.
|
|
func TestPathTracerStubWGConfigureNoOp(t *testing.T) {
|
|
payload := WGConfigPayload{
|
|
SessionID: "test-session",
|
|
PrivateKey: "privkey",
|
|
LocalAddress: "10.0.0.1/32",
|
|
ListenPort: 51820,
|
|
Peers: []WGPeerEntry{
|
|
{
|
|
PublicKey: "peerkey",
|
|
Endpoint: "1.2.3.4:51820",
|
|
AllowedIPs: "0.0.0.0/0",
|
|
PersistentKeepalive: 25,
|
|
},
|
|
},
|
|
EnableIPForwarding: false,
|
|
}
|
|
if err := WGConfigure(payload); err != nil {
|
|
t.Errorf("WGConfigure stub must return nil, got: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestWGTeardownNoOp verifies WGTeardown does not panic or error on non-Windows.
|
|
func TestPathTracerStubWGTeardownNoOp(t *testing.T) {
|
|
// Should complete without panic.
|
|
WGTeardown()
|
|
}
|
|
|
|
// TestWGIsActiveReturnsFalse ensures the stub correctly reports inactive.
|
|
func TestPathTracerStubWGIsActiveReturnsFalse(t *testing.T) {
|
|
if WGIsActive() {
|
|
t.Error("WGIsActive stub must return false on non-Windows")
|
|
}
|
|
}
|
|
|
|
// TestWGStatusNotSupported verifies the stub reports an unsupported-platform message.
|
|
func TestPathTracerStubWGStatusNotSupported(t *testing.T) {
|
|
status := WGStatus()
|
|
if status == "" {
|
|
t.Error("WGStatus stub must return a non-empty string")
|
|
}
|
|
if !strings.Contains(status, "not supported") {
|
|
t.Errorf("WGStatus stub should mention unsupported platform, got %q", status)
|
|
}
|
|
}
|
|
|
|
// TestWGSetupJSONExactStubError verifies the stub error string matches server expectations.
|
|
func TestPathTracerStubWGSetupJSONExactError(t *testing.T) {
|
|
raw := WGSetupJSON()
|
|
if !strings.Contains(raw, "Windows-only") {
|
|
t.Errorf("stub error should mention Windows-only, got %q", raw)
|
|
}
|
|
}
|
|
|
|
// TestWGConfigureRejectsEmptyPayloadOnStub is a no-op but documents stub behaviour.
|
|
func TestPathTracerStubWGConfigureAcceptsPayload(t *testing.T) {
|
|
err := WGConfigure(WGConfigPayload{
|
|
SessionID: "stub-session",
|
|
LocalAddress: "10.66.0.2/24",
|
|
ListenPort: 51820,
|
|
})
|
|
if err != nil {
|
|
t.Errorf("WGConfigure stub must be no-op, got %v", err)
|
|
}
|
|
}
|