Skip to content

Commit

Permalink
Add empty test data check
Browse files Browse the repository at this point in the history
  • Loading branch information
winebarrel committed Nov 2, 2024
1 parent 44425a7 commit a9d0b5e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [1.3.2] - 2024-11-02

### Added

* Add empty test data check.

## [1.3.2] - 2024-11-02

### Changed

* Use "JSON Lines" instead of "NDJSON".
Expand Down
10 changes: 10 additions & 0 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ func NewData(options *Options, agentNum uint64) (*Data, error) {
return nil, fmt.Errorf("failed to open test data - %s (%w)", dataFile, err)
}

fileInfo, err := file.Stat()

if err != nil {
return nil, fmt.Errorf("failed to get test data file info - %s (%w)", dataFile, err)
}

if fileInfo.Size() == 0 {
return nil, fmt.Errorf("test data is empty - %s", dataFile)
}

if options.Random {
err = util.RandSeek(file)

Expand Down
18 changes: 18 additions & 0 deletions data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,21 @@ func Test_Data_WithCommentOut(t *testing.T) {
_, err = data.Next()
assert.ErrorIs(err, qube.EOD)
}

func Test_Data_Empty(t *testing.T) {
assert := assert.New(t)

f, _ := os.CreateTemp("", "")
defer os.Remove(f.Name())
f.Sync()

options := &qube.Options{
DataOptions: qube.DataOptions{
DataFiles: []string{f.Name()},
Key: "q",
},
}

_, err := qube.NewData(options, 0)
assert.ErrorContains(err, "test data is empty")
}

0 comments on commit a9d0b5e

Please sign in to comment.