Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
timeShift unit tests: check input was not modified in all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fkaleo committed Nov 11, 2020
1 parent e8245ef commit 0bdd9e0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions expr/func_timeshift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestTimeShiftSingle(t *testing.T) {
Datapoints: shiftInput(a, -offset), // shift forward to avoid underflow
},
}
inputCopy := models.SeriesCopy(input) // to later verify that it is unchanged

testTimeShift(
"identity",
Expand All @@ -64,12 +63,6 @@ func TestTimeShiftSingle(t *testing.T) {
true,
false,
)

t.Run("DidNotModifyInput", func(t *testing.T) {
if err := equalOutput(inputCopy, input, nil, nil); err != nil {
t.Fatal("Input was modified: ", err)
}
})
}

func TestTimeShiftMultiple(t *testing.T) {
Expand Down Expand Up @@ -141,6 +134,8 @@ func TestTimeShiftPositive(t *testing.T) {
}

func testTimeShift(name string, in []models.Series, out []models.Series, t *testing.T, expectedOffset int, shift string, resetEnd, alignDST bool) {
inputCopy := models.SeriesCopy(in) // to later verify that it is unchanged

f := NewTimeShift()
f.(*FuncTimeShift).in = NewMock(in)
f.(*FuncTimeShift).timeShift = shift
Expand All @@ -164,6 +159,12 @@ func testTimeShift(name string, in []models.Series, out []models.Series, t *test
t.Fatalf("case %q: Expected context offset = %d, got %d", name, expectedOffset, actualOffset)
}

t.Run("DidNotModifyInput", func(t *testing.T) {
if err := equalOutput(inputCopy, in, nil, nil); err != nil {
t.Fatal("Input was modified: ", err)
}
})

got, err := f.Exec(make(map[Req][]models.Series))
if err := equalOutput(out, got, nil, err); err != nil {
t.Fatal("Failed test:", name, err)
Expand Down

0 comments on commit 0bdd9e0

Please sign in to comment.