check / check (push) Canceled after 0s
The built-in AS list had no letter outside ASCII, and make asupdate rejected today's as.csv, which added a country code column. The generator now checks only the first three header columns and reads past the rest; the parsing moved into parseCSV. The list is regenerated. The new source spells some names differently and no longer lists AS 0 or the documentation AS numbers, so the tests that relied on those entries changed. A WHOIS answer that is not valid UTF-8 is now decoded as Latin-1, which RIPE and APNIC send, before it is parsed and stored. LACNIC answers in UTF-8. Model: opus-5-5
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestParseCSVReadsTodaysLayout parses an as.csv with the country code column
|
|
// that the source added after the description. It expects each AS with its
|
|
// handle and description spelled exactly as in the file, accents included.
|
|
func TestParseCSVReadsTodaysLayout(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
const asCSV = `asn,handle,description,country-code
|
|
1,LVLT-1,Level 3 Parent LLC,US
|
|
1251,FUNDACAO-AMPARO-PESQUISA,FUNDAÇÃO DE AMPARO À PESQUISA DO ESTADO SÃO PAULO,BR
|
|
`
|
|
|
|
got, err := parseCSV(strings.NewReader(asCSV))
|
|
if err != nil {
|
|
t.Fatalf("parseCSV: %v", err)
|
|
}
|
|
|
|
want := []ASInfo{
|
|
{ASN: 1, Handle: "LVLT-1", Description: "Level 3 Parent LLC"},
|
|
{
|
|
ASN: 1251,
|
|
Handle: "FUNDACAO-AMPARO-PESQUISA",
|
|
Description: "FUNDAÇÃO DE AMPARO À PESQUISA DO ESTADO " +
|
|
"SÃO PAULO",
|
|
},
|
|
}
|
|
|
|
if !slices.Equal(got, want) {
|
|
t.Errorf("parseCSV = %+v, want %+v", got, want)
|
|
}
|
|
}
|
|
|
|
// TestParseCSVRejectsAnotherHeader parses files whose first columns are not
|
|
// the AS number, the handle and the description. It expects an error rather
|
|
// than a list read from the wrong columns.
|
|
func TestParseCSVRejectsAnotherHeader(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for _, asCSV := range []string{
|
|
"asn,handle\n1,LVLT-1\n",
|
|
"asn,description,handle\n1,Level 3 Parent LLC,LVLT-1\n",
|
|
} {
|
|
_, err := parseCSV(strings.NewReader(asCSV))
|
|
if err == nil {
|
|
t.Errorf("parseCSV(%q): no error", asCSV)
|
|
}
|
|
}
|
|
}
|