package csvparser import ( "errors" "os" "path/filepath" "testing" ) // TestCsvParser tests the correct function of the CSV file parser func TestCsvParser(t *testing.T) { check := []CsvLine{ {Code: "Foo", Name: "bar"}, {Code: "Bla", Name: "blub"}, {Code: "Nom", Name: "LoL"}, {Code: "123", Name: "256"}, {Code: "Rawr", Name: "Bla"}, {Code: "Lorem ipsum", Name: "dolor \"sit amet"}, {Code: "Smile", Name: "😇"}, {Code: "empty", Name: ""}, } parsed, err := ParseFile(filepath.Join("..", "..", "test", "data", "csvparser.csv")) if err != nil { t.Fatalf("Got error: %+v", err) } if len(parsed) != len(check) { t.Fatalf("Slice-length mismatch, got %d, expected %d", len(parsed), len(check)) } for i, item := range check { if item != parsed[i] { t.Errorf("Got wrong CSV line, got %s, expected %s", parsed[i], item) } } } func TestCsvParserFileError(t *testing.T) { _, err := ParseFile("nonexisting") if err == nil { t.Fatalf("Got no error") } if !errors.Is(err, os.ErrNotExist) { t.Errorf("Got error %+v, expected %+v", err, os.ErrNotExist) } }