Re-vendor the shared files from sneak/prompts at dd4027b (closes #52)
check / check (push) Waiting to run
check / check (push) Waiting to run
Takes .golangci.yml, .dockerignore, .gitignore, .editorconfig, the workflow and REPO_POLICIES.md from sneak/prompts dd4027b, keeping this repository's own entries after the shared content. Lint (golangci-lint v2.14.0) and test become Dockerfile phases that script/lint and script/test build alone and uncached; the image build depends on both, and script/cibuild bootstraps, runs script/check, then builds the image. The agent guidance file moves to AGENTS.md. The Go code is fixed for what the new configuration finds; reads that iterate rows now also report an iteration error. Model: opus-5-5
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// Package asinfo provides information about Autonomous Systems (AS)
|
||||
package asinfo
|
||||
|
||||
import (
|
||||
@@ -54,7 +53,9 @@ func initRegistry() {
|
||||
}
|
||||
|
||||
var asInfos []Info
|
||||
if err := json.Unmarshal(jsonData, &asInfos); err != nil {
|
||||
|
||||
err = json.Unmarshal(jsonData, &asInfos)
|
||||
if err != nil {
|
||||
panic("failed to unmarshal embedded AS data: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -137,6 +138,7 @@ func Search(query string) []Info {
|
||||
defer defaultRegistry.mu.RUnlock()
|
||||
|
||||
var results []Info
|
||||
|
||||
for _, info := range defaultRegistry.byASN {
|
||||
if contains(info.Handle, query) || contains(info.Description, query) {
|
||||
results = append(results, *info)
|
||||
|
||||
+52
-16
@@ -1,10 +1,15 @@
|
||||
package asinfo
|
||||
package asinfo_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.eeqj.de/sneak/routewatch/pkg/asinfo"
|
||||
)
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
asn int
|
||||
@@ -38,20 +43,26 @@ func TestGet(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
info, ok := Get(tt.asn)
|
||||
t.Parallel()
|
||||
|
||||
info, ok := asinfo.Get(tt.asn)
|
||||
if ok != tt.wantOK {
|
||||
t.Errorf("Get(%d) ok = %v, want %v", tt.asn, ok, tt.wantOK)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if ok && info.Description != tt.wantDesc {
|
||||
t.Errorf("Get(%d) description = %q, want %q", tt.asn, info.Description, tt.wantDesc)
|
||||
t.Errorf("Get(%d) description = %q, want %q",
|
||||
tt.asn, info.Description, tt.wantDesc)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDescription(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
asn int
|
||||
want string
|
||||
@@ -62,7 +73,10 @@ func TestGetDescription(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
if got := GetDescription(tt.asn); got != tt.want {
|
||||
t.Parallel()
|
||||
|
||||
got := asinfo.GetDescription(tt.asn)
|
||||
if got != tt.want {
|
||||
t.Errorf("GetDescription(%d) = %q, want %q", tt.asn, got, tt.want)
|
||||
}
|
||||
})
|
||||
@@ -70,6 +84,8 @@ func TestGetDescription(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetHandle(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
asn int
|
||||
want string
|
||||
@@ -81,7 +97,10 @@ func TestGetHandle(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
if got := GetHandle(tt.asn); got != tt.want {
|
||||
t.Parallel()
|
||||
|
||||
got := asinfo.GetHandle(tt.asn)
|
||||
if got != tt.want {
|
||||
t.Errorf("GetHandle(%d) = %q, want %q", tt.asn, got, tt.want)
|
||||
}
|
||||
})
|
||||
@@ -89,18 +108,23 @@ func TestGetHandle(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTotal(t *testing.T) {
|
||||
total := Total()
|
||||
t.Parallel()
|
||||
|
||||
total := asinfo.Total()
|
||||
if total < 100000 {
|
||||
t.Errorf("Total() = %d, expected > 100000", total)
|
||||
}
|
||||
|
||||
// Verify it's consistent
|
||||
if total2 := Total(); total2 != total {
|
||||
total2 := asinfo.Total()
|
||||
if total2 != total {
|
||||
t.Errorf("Total() returned different values: %d vs %d", total, total2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearch(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
query string
|
||||
@@ -130,16 +154,21 @@ func TestSearch(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
results := Search(tt.query)
|
||||
t.Parallel()
|
||||
|
||||
results := asinfo.Search(tt.query)
|
||||
if len(results) < tt.wantMin {
|
||||
t.Errorf("Search(%q) returned %d results, want at least %d", tt.query, len(results), tt.wantMin)
|
||||
t.Errorf("Search(%q) returned %d results, want at least %d",
|
||||
tt.query, len(results), tt.wantMin)
|
||||
}
|
||||
|
||||
// Verify all results contain the query
|
||||
if tt.query != "" {
|
||||
for _, r := range results {
|
||||
if !contains(r.Handle, tt.query) && !contains(r.Description, tt.query) {
|
||||
t.Errorf("Search result ASN %d doesn't contain query %q", r.ASN, tt.query)
|
||||
if !strings.Contains(r.Handle, tt.query) &&
|
||||
!strings.Contains(r.Description, tt.query) {
|
||||
t.Errorf("Search result ASN %d doesn't contain query %q",
|
||||
r.ASN, tt.query)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,13 +177,17 @@ func TestSearch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDataIntegrity(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Verify no duplicate ASNs
|
||||
all := All()
|
||||
all := asinfo.All()
|
||||
seen := make(map[int]bool)
|
||||
|
||||
for _, info := range all {
|
||||
if seen[info.ASN] {
|
||||
t.Errorf("Duplicate ASN found: %d", info.ASN)
|
||||
}
|
||||
|
||||
seen[info.ASN] = true
|
||||
}
|
||||
|
||||
@@ -163,6 +196,7 @@ func TestDataIntegrity(t *testing.T) {
|
||||
if info.Handle == "" && info.ASN != 0 {
|
||||
t.Errorf("ASN %d has empty handle", info.ASN)
|
||||
}
|
||||
|
||||
if info.Description == "" {
|
||||
t.Errorf("ASN %d has empty description", info.ASN)
|
||||
}
|
||||
@@ -174,8 +208,9 @@ func BenchmarkGet(b *testing.B) {
|
||||
asns := []int{1, 15169, 13335, 32934, 8075, 16509}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Get(asns[i%len(asns)])
|
||||
|
||||
for i := range b.N {
|
||||
asinfo.Get(asns[i%len(asns)])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +218,8 @@ func BenchmarkSearch(b *testing.B) {
|
||||
queries := []string{"Google", "Amazon", "Microsoft", "University"}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Search(queries[i%len(queries)])
|
||||
|
||||
for i := range b.N {
|
||||
asinfo.Search(queries[i%len(queries)])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user