Skip to content

Commit

Permalink
Updating based on ai suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
madflojo committed Oct 23, 2023
1 parent df7e99a commit db3b966
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ build:
docker run --rm -v `pwd`:/build -w /build/functions/build/init tinygo/tinygo:0.25.0 tinygo build -o /build/functions/build/init.wasm -target wasi /build/functions/src/init/main.go
docker run --rm -v `pwd`:/build -w /build/functions/build/data/fetch tinygo/tinygo:0.25.0 tinygo build -o /build/functions/build/fetch.wasm -target wasi /build/functions/src/data/fetch/main.go

.PHONY: tests
tests:
## Run tests
mkdir -p coverage
Expand Down
3 changes: 2 additions & 1 deletion pkg/airport/airport_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package airport

import (
"reflect"
"testing"
)

Expand Down Expand Up @@ -187,7 +188,7 @@ func TestAirport(t *testing.T) {
return
}

if result != tc.expected {
if !reflect.DeepEqual(result, tc.expected) {
t.Errorf("Expected %v, got %v", tc.expected, result)
}
})
Expand Down
41 changes: 24 additions & 17 deletions pkg/airport/parsers/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,35 @@ func (p *Parser) Parse() ([]airport.Airport, error) {
// Create a new CSV Reader
reader := csv.NewReader(p.reader)

// Read the CSV file
rec, err := reader.ReadAll()
if err != nil {
return nil, fmt.Errorf("unable to read csv data - %w", err)
}

// Create a slice of Airports
airports := make([]airport.Airport, 0, len(rec))
var airports []airport.Airport

// Iterate over the CSV records
for _, r := range rec {
// Convert the record to an Airport
a, err := RecordToAirport(r)
// Read each line of the CSV file
for {
// Read the CSV file
rec, err := reader.Read()
if err != nil {
// Skip headers and records with not enough fields
if err == ErrIsHeader || err == ErrNotEnoughFields {
continue
// Breakout if we've reached the end of the file
if err == io.EOF {
break
}
return nil, fmt.Errorf("unable to read csv data - %w", err)
}

// Iterate over the CSV records
for _, r := range rec {
// Convert the record to an Airport
a, err := RecordToAirport(r)

Check failure on line 51 in pkg/airport/parsers/csv/csv.go

View workflow job for this annotation

GitHub Actions / tests

cannot use r (variable of type string) as []string value in argument to RecordToAirport

Check failure on line 51 in pkg/airport/parsers/csv/csv.go

View workflow job for this annotation

GitHub Actions / golangci

cannot use r (variable of type string) as []string value in argument to RecordToAirport (typecheck)
if err != nil {
// Skip headers and records with not enough fields
if err == ErrIsHeader || err == ErrNotEnoughFields {
continue
}
return nil, fmt.Errorf("unable to convert record to airport - %w", err)
}
return nil, fmt.Errorf("unable to convert record to airport - %w", err)
// Append the Airport to the slice
airports = append(airports, a)
}
// Append the Airport to the slice
airports = append(airports, a)
}

// Return the slice of Airports
Expand Down

0 comments on commit db3b966

Please sign in to comment.