package platform_test

import (
	"ekdns/platform"
	"os"
	"strings"
	"testing"
)

// T007-1: GetHostsFilePath returns a non-empty path with no error on the current OS.
func TestGetHostsFilePathReturnsPath(t *testing.T) {
	path, err := platform.GetHostsFilePath()
	if err != nil {
		t.Fatalf("GetHostsFilePath returned unexpected error: %v", err)
	}
	if path == "" {
		t.Error("GetHostsFilePath returned empty path")
	}
}

// T007-2: The returned path exists on the filesystem.
func TestGetHostsFilePathExists(t *testing.T) {
	path, err := platform.GetHostsFilePath()
	if err != nil {
		t.Fatalf("GetHostsFilePath returned unexpected error: %v", err)
	}
	if _, err := os.Stat(path); err != nil {
		t.Errorf("hosts file path %q does not exist or cannot be accessed: %v", path, err)
	}
}

// T024-1: GetHostsFilePath returns a path that is an absolute path (contains a
// directory separator), ensuring the error messages that embed the path are descriptive.
func TestGetHostsFilePathIsAbsolute(t *testing.T) {
	path, err := platform.GetHostsFilePath()
	if err != nil {
		t.Fatalf("GetHostsFilePath returned unexpected error: %v", err)
	}
	if !strings.ContainsAny(path, `/\`) {
		t.Errorf("expected an absolute path containing a directory separator, got %q", path)
	}
}

// T024-2: GetHostsFilePath function signature returns (string, error) — process
// termination (os.Exit, log.Fatal, term()) is absent from the platform package.
// This is verified statically by T023 grep/vet; the runtime counterpart is that the
// function can be called without panicking or exiting.
func TestGetHostsFilePathDoesNotPanic(t *testing.T) {
	defer func() {
		if r := recover(); r != nil {
			t.Errorf("GetHostsFilePath panicked: %v", r)
		}
	}()
	platform.GetHostsFilePath() //nolint:errcheck // return values checked in other tests
}
