package client

import (
	"reflect"
	"testing"
)

func TestParseDNSJSON(t *testing.T) {
	cfg := parseDNSJSON(`{"servers":"1.1.1.1, 8.8.8.8","search":"corp.local, example.com"}`)
	wantServers := []string{"1.1.1.1", "8.8.8.8"}
	wantSearch := []string{"corp.local", "example.com"}
	if !reflect.DeepEqual(cfg.Servers, wantServers) {
		t.Fatalf("servers: %v", cfg.Servers)
	}
	if !reflect.DeepEqual(cfg.SearchDomains, wantSearch) {
		t.Fatalf("search: %v", cfg.SearchDomains)
	}
}

func TestParseDNSJSONInvalid(t *testing.T) {
	cfg := parseDNSJSON(`not-json`)
	if len(cfg.Servers) != 0 || len(cfg.SearchDomains) != 0 {
		t.Fatalf("invalid json should yield empty config: %+v", cfg)
	}
}

func TestParseDNSJSONSkipsEmptyFields(t *testing.T) {
	cfg := parseDNSJSON(`{"servers":"","search":""}`)
	if len(cfg.Servers) != 0 || len(cfg.SearchDomains) != 0 {
		t.Fatalf("empty fields should be skipped: %+v", cfg)
	}
}
