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) } } }