package platform_test

import (
	"ekdns/platform"
	"errors"
	"testing"
)

func TestFakeNetworkDiscoverer_ReturnsInfo(t *testing.T) {
	fake := &platform.FakeNetworkDiscoverer{
		Info: platform.NetworkInfo{
			DNSServers: []string{"10.0.0.1", "10.0.0.2"},
			Gateway:    "10.0.0.1",
			Interface:  "eth0",
		},
	}

	info, err := fake.Discover()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if len(info.DNSServers) != 2 {
		t.Errorf("expected 2 DNS servers, got %d", len(info.DNSServers))
	}
	if info.DNSServers[0] != "10.0.0.1" {
		t.Errorf("DNSServers[0]: got %q, want %q", info.DNSServers[0], "10.0.0.1")
	}
	if info.DNSServers[1] != "10.0.0.2" {
		t.Errorf("DNSServers[1]: got %q, want %q", info.DNSServers[1], "10.0.0.2")
	}
	if info.Gateway != "10.0.0.1" {
		t.Errorf("Gateway: got %q, want %q", info.Gateway, "10.0.0.1")
	}
	if info.Interface != "eth0" {
		t.Errorf("Interface: got %q, want %q", info.Interface, "eth0")
	}
}

func TestFakeNetworkDiscoverer_ReturnsError(t *testing.T) {
	fake := &platform.FakeNetworkDiscoverer{
		Err: errors.New("discovery failed"),
	}

	_, err := fake.Discover()
	if err == nil {
		t.Fatal("expected error, got nil")
	}
	if err.Error() != "discovery failed" {
		t.Errorf("error message: got %q, want %q", err.Error(), "discovery failed")
	}
}

func TestFakeNetworkDiscoverer_EmptyInfo(t *testing.T) {
	fake := &platform.FakeNetworkDiscoverer{}

	info, err := fake.Discover()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if len(info.DNSServers) != 0 {
		t.Errorf("expected empty DNSServers, got %v", info.DNSServers)
	}
	if info.Gateway != "" {
		t.Errorf("expected empty Gateway, got %q", info.Gateway)
	}
}
