Skip to content

Commit

Permalink
Merge pull request #47 from BenB196/staging
Browse files Browse the repository at this point in the history
Staging to master
  • Loading branch information
BenB196 authored Nov 3, 2020
2 parents 0ce7ba0 + 4734edd commit 06311ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.3
0.2.4
28 changes: 21 additions & 7 deletions ffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,10 @@ func GetFileEvents(authData AuthData, ffsURI string, query Query) (*[]FileEvent,
fileEvents = append(fileEvents, *csvLineToFileEvent(lineContent))
} else {
//Validate that the columns have not changed
equal := equal(lineContent, csvHeaders)
err = equal(lineContent, csvHeaders)

if !equal {
if err != nil {
println(err)
panic(errors.New("number of columns in CSV file does not match expected number, API changed, panicking to keep data integrity. New CSV columns: " + strings.Join(lineContent, ",")))
}
}
Expand All @@ -665,16 +666,29 @@ func GetFileEvents(authData AuthData, ffsURI string, query Query) (*[]FileEvent,
Calculate the difference between two different slices
Used in this case to tell if the csv columns have changed
*/
func equal(slice1 []string, slice2 []string) bool {
func equal(slice1 []string, slice2 []string) error {
if len(slice1) != len(slice2) {
return false
return errors.New("slices and CSV header sizes do not match")
}

//loop through slices to check values
for i, v := range slice1 {
if v != slice2[i] {
return false
//if last element in slice1, remove potential eol char
if i == len(slice1) - 1 {
v = strings.Replace(v, "\r\n", "", -1)
v = strings.Replace(v, "\r", "", -1)
v = strings.Replace(v, "\n", "", -1)

//we don't need to worry about slice2, its static
if v != slice2[i] {
return errors.New("column order/naming does not match")
}
} else {
if v != slice2[i] {
return errors.New("column order/naming does not match")
}
}
}

return true
return nil
}

0 comments on commit 06311ec

Please sign in to comment.