GetPeaksForSegment: add extra invalid arg check
This commit is contained in:
parent
a9ea462b41
commit
6dde29cdcf
|
@ -367,7 +367,7 @@ outer:
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MediaSetService) GetPeaksForSegment(ctx context.Context, id uuid.UUID, startFrame, endFrame int64, numBins int) ([]int16, error) {
|
func (s *MediaSetService) GetPeaksForSegment(ctx context.Context, id uuid.UUID, startFrame, endFrame int64, numBins int) ([]int16, error) {
|
||||||
if startFrame < 0 || endFrame < 0 || numBins <= 0 {
|
if startFrame < 0 || endFrame < 0 || numBins <= 0 || startFrame == endFrame {
|
||||||
s.logger.With("startFrame", startFrame, "endFrame", endFrame, "numBins", numBins).Error("invalid arguments")
|
s.logger.With("startFrame", startFrame, "endFrame", endFrame, "numBins", numBins).Error("invalid arguments")
|
||||||
return nil, errors.New("invalid arguments")
|
return nil, errors.New("invalid arguments")
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,15 @@ func TestPeaksForSegment(t *testing.T) {
|
||||||
wantPeaks []int16
|
wantPeaks []int16
|
||||||
wantErr string
|
wantErr string
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
name: "NOK, invalid arguments",
|
||||||
|
fixturePath: "testdata/tone-44100-stereo-int16.raw",
|
||||||
|
startFrame: 0,
|
||||||
|
endFrame: 0,
|
||||||
|
channels: 2,
|
||||||
|
numBins: 1,
|
||||||
|
wantErr: "invalid arguments",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "OK, entire fixture, stereo, 1 bin",
|
name: "OK, entire fixture, stereo, 1 bin",
|
||||||
fixturePath: "testdata/tone-44100-stereo-int16.raw",
|
fixturePath: "testdata/tone-44100-stereo-int16.raw",
|
||||||
|
@ -146,7 +155,6 @@ func TestPeaksForSegment(t *testing.T) {
|
||||||
// store is passed the mediaSetID and returns a mediaSet
|
// store is passed the mediaSetID and returns a mediaSet
|
||||||
store := &mocks.Store{}
|
store := &mocks.Store{}
|
||||||
store.On("GetMediaSet", mock.Anything, mediaSet.ID).Return(mediaSet, nil)
|
store.On("GetMediaSet", mock.Anything, mediaSet.ID).Return(mediaSet, nil)
|
||||||
defer store.AssertExpectations(t)
|
|
||||||
|
|
||||||
// fileStore is passed the expected byte range, and returns an io.Reader
|
// fileStore is passed the expected byte range, and returns an io.Reader
|
||||||
fileStore := &mocks.FileStore{}
|
fileStore := &mocks.FileStore{}
|
||||||
|
@ -158,6 +166,8 @@ func TestPeaksForSegment(t *testing.T) {
|
||||||
peaks, err := service.GetPeaksForSegment(context.Background(), mediaSet.ID, tc.startFrame, tc.endFrame, tc.numBins)
|
peaks, err := service.GetPeaksForSegment(context.Background(), mediaSet.ID, tc.startFrame, tc.endFrame, tc.numBins)
|
||||||
|
|
||||||
if tc.wantErr == "" {
|
if tc.wantErr == "" {
|
||||||
|
defer store.AssertExpectations(t)
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, tc.wantPeaks, peaks)
|
assert.Equal(t, tc.wantPeaks, peaks)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue