-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: aswinkarthik <[email protected]>
- Loading branch information
1 parent
aca0154
commit 239708f
Showing
7 changed files
with
155 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package digest | ||
|
||
import ( | ||
"encoding/csv" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetNextNLines(t *testing.T) { | ||
t.Run("should get given number of lines from csv", func(t *testing.T) { | ||
var csvBuilder strings.Builder | ||
const totalLines = 1000 | ||
for i := 0; i < totalLines; i++ { | ||
csvBuilder.WriteString(fmt.Sprintf("%d,random-col-1,random-col-2\n", i)) | ||
} | ||
|
||
csvFile := csv.NewReader(strings.NewReader(csvBuilder.String())) | ||
|
||
lines, eofReached, err := getNextNLines(csvFile) | ||
|
||
assert.Len(t, lines, bufferSize) | ||
assert.False(t, eofReached) | ||
assert.NoError(t, err) | ||
|
||
for i := 0; i < bufferSize; i++ { | ||
expected := []string{strconv.Itoa(i), "random-col-1", "random-col-2"} | ||
assert.Equal(t, expected, lines[i]) | ||
} | ||
|
||
lines, eofReached, err = getNextNLines(csvFile) | ||
|
||
assert.Len(t, lines, totalLines-bufferSize) | ||
assert.True(t, eofReached) | ||
assert.NoError(t, err) | ||
|
||
for i := 0; i < totalLines-bufferSize; i++ { | ||
expected := []string{strconv.Itoa(i + bufferSize), "random-col-1", "random-col-2"} | ||
assert.Equal(t, expected, lines[i]) | ||
} | ||
}) | ||
|
||
t.Run("should throw error if not a valid csv", func(t *testing.T) { | ||
sampleInvalidCSV := `1,2,3 | ||
4,5,6 | ||
random-stuff | ||
7,8,9` | ||
csvFile := csv.NewReader(strings.NewReader(sampleInvalidCSV)) | ||
|
||
_, _, err := getNextNLines(csvFile) | ||
|
||
assert.Error(t, err) | ||
}) | ||
} |