package geo

import (
	"os"
	"testing"
)

func TestPostgresResolverLookup(t *testing.T) {
	dsn := os.Getenv("GEOIP_TEST_DATABASE_URL")
	if dsn == "" {
		t.Skip("GEOIP_TEST_DATABASE_URL not set; skipping Postgres integration test")
	}

	resolver, err := NewResolver(Config{
		Backend:     BackendPostgres,
		DatabaseURL: dsn,
	})
	if err != nil {
		t.Fatalf("failed to init postgres resolver: %v", err)
	}
	defer resolver.Close()

	loc, err := resolver.Lookup("1.1.1.1")
	if err != nil {
		t.Fatalf("lookup failed: %v", err)
	}
	if loc.IP == "" {
		t.Fatalf("expected resolved IP, got empty")
	}
}
