Files
addrkit/internal/seed/seed_test.go
T
Maksim Totmin 7b152c7fb3 addrkit: deterministic address resolution service (Go)
- domain: address normalization/parsing, matching with explicit statuses
- adapters: SQLite registry store, ArcGIS outages client, optional LLM rewriter, HTTP API
- seed pipeline with duplicate handling and unparsed reporting
- CLI (seed/verify/resolve), systemd unit, OpenAPI contract, tests
2026-10-09 21:40:46 +07:00

56 lines
1.6 KiB
Go

package seed
import (
"strings"
"testing"
)
func TestReadBulkNDJSON(t *testing.T) {
input := `{"index": {"_index": "address_registry", "_id": "a1"}}
{"address": "Станционная улица 1/1", "district_name": "Ленинский"}
{"index": {"_id": "a2"}}
{"address": "Искитимская улица 5", "district_name": "Кировский"}
{"address": "Третья улица 7"}
`
src, err := ReadBulkNDJSON(strings.NewReader(input))
if err != nil {
t.Fatalf("ReadBulkNDJSON: %v", err)
}
if len(src) != 3 {
t.Fatalf("got %d sources, want 3", len(src))
}
if src[0].ID != "a1" || src[0].District != "Ленинский" {
t.Errorf("first source = %+v", src[0])
}
if src[2].Address != "Третья улица 7" {
t.Errorf("bare source not read: %+v", src[2])
}
}
func TestBuild(t *testing.T) {
sources := []Source{
{ID: "1", Address: "Станционная улица 1/1"},
{ID: "2", Address: "Искитимская улица 5"},
{ID: "3", Address: "Станционная улица"}, // no house -> unparsed
}
entries, stats := Build(sources)
if stats.Total != 3 {
t.Errorf("Total = %d, want 3", stats.Total)
}
if stats.Parsed != 2 {
t.Errorf("Parsed = %d, want 2", stats.Parsed)
}
if stats.Unparsed != 1 {
t.Errorf("Unparsed = %d, want 1", stats.Unparsed)
}
if len(entries) != 3 {
t.Errorf("entries = %d, want 3", len(entries))
}
// Two distinct streets: "станционная" and "искитимская".
if stats.DistinctStreets != 2 {
t.Errorf("DistinctStreets = %d, want 2", stats.DistinctStreets)
}
}