Skip to content

Commit 3833744

Browse files
authored
add tiny test start/end time validation (#1549)
1 parent 63fcb37 commit 3833744

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

wasp/benchspy/basic.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ func (b *BasicData) Validate() error {
121121
return errors.New("test end time is missing. We cannot query Loki without a time range. Please set it and try again")
122122
}
123123

124+
if b.TestEnd.Before(b.TestStart) {
125+
return errors.New("test end time is before test start time. Please set valid times and try again")
126+
}
127+
if b.TestEnd.Sub(b.TestStart) < time.Second {
128+
return errors.New("test duration is less than a second. Please set a valid time range and try again")
129+
}
130+
124131
if len(b.GeneratorConfigs) == 0 {
125132
return errors.New("generator configs are missing. At least one is required. Please set them and try again")
126133
}

wasp/benchspy/basic_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,33 @@ func TestBenchSpy_TestBasicData_Validate(t *testing.T) {
277277
wantErr: true,
278278
errMsg: "generator configs are missing",
279279
},
280+
{
281+
name: "test start and end time are the same",
282+
bd: &BasicData{
283+
TestStart: time.Now(),
284+
TestEnd: time.Now(),
285+
},
286+
wantErr: true,
287+
errMsg: "test duration is less than a second",
288+
},
289+
{
290+
name: "test end time before start time",
291+
bd: &BasicData{
292+
TestStart: time.Now().Add(time.Hour),
293+
TestEnd: time.Now(),
294+
},
295+
wantErr: true,
296+
errMsg: "test end time is before test start time",
297+
},
298+
{
299+
name: "test end time are start time < 1s apart",
300+
bd: &BasicData{
301+
TestStart: time.Now(),
302+
TestEnd: time.Now().Add(time.Second - time.Millisecond),
303+
},
304+
wantErr: true,
305+
errMsg: "test duration is less than a second",
306+
},
280307
}
281308

282309
for _, tt := range tests {

0 commit comments

Comments
 (0)