-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_test.go
66 lines (56 loc) · 1.31 KB
/
delete_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package influxqb
import (
"fmt"
"github.com/influxdata/influxql"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
/*
*/
var testDeleteBuilder = []struct {
d string
b BuilderIf
s string
e bool
}{
{"Delete all from mesurement",
NewDeleteBuilder().From("cpu"),
"DELETE FROM cpu",
false,
},
{"Delete from mesurement where ",
NewDeleteBuilder().
From("cpu").
Where(LessThan(&Field{Name: "time"}, time.Date(2000, 01, 01, 0, 0, 0, 0, time.UTC))),
"DELETE FROM cpu WHERE (time < '2000-01-01T00:00:00Z')",
false,
},
{"Delete all WHERE time < 2000",
NewDeleteBuilder().
Where(LessThan(&Field{Name: "time"}, time.Date(2000, 01, 01, 0, 0, 0, 0, time.UTC))),
"DELETE FROM /.*/ WHERE (time < '2000-01-01T00:00:00Z')",
false,
},
{"Delete all WHERE time < 2000 with MathExpr",
NewDeleteBuilder().
Where(&Math{Expr: []interface{}{
&Field{Name: "time"}, influxql.LT, time.Date(2000, 01, 01, 0, 0, 0, 0, time.UTC)}},
),
"DELETE FROM /.*/ WHERE (time < '2000-01-01T00:00:00Z')",
false,
},
}
func TestDeleteBuilder(t *testing.T) {
for i, sample := range testDeleteBuilder {
s, err := sample.b.Build()
fmt.Print("Test ", i, ": ", sample.d)
if sample.e {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, sample.s, s)
fmt.Println(" [OK]")
}
}