-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment_test.go
74 lines (59 loc) · 2.36 KB
/
comment_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
67
68
69
70
71
72
73
74
package db
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseCommentTrailingComment(t *testing.T) {
expected := &ParsedComment{
Comment: "/* comment */",
Query: "SELECT * FROM table ORDER BY foo LIMIT 10 OFFSET 10",
}
parsed := parseComment("SELECT * FROM table ORDER BY foo LIMIT 10 OFFSET 10 /* comment */")
assert.Equal(t, expected, parsed)
}
func TestParseCommentLeadingComment(t *testing.T) {
expected := &ParsedComment{
Comment: "/* comment */",
Query: "SELECT * FROM table ORDER BY foo LIMIT 10 OFFSET 10",
}
parsed := parseComment("/* comment */ SELECT * FROM table ORDER BY foo LIMIT 10 OFFSET 10")
assert.Equal(t, expected, parsed)
}
func TestParseCommentKeyValueComment(t *testing.T) {
expected := &ParsedComment{
Comment: "/*app:worker-foo,job:AlertWorker*/",
Query: "SELECT * FROM table ORDER BY foo LIMIT 10 OFFSET 10",
}
parsed := parseComment("SELECT * FROM table ORDER BY foo LIMIT 10 OFFSET 10/*app:worker-foo,job:AlertWorker*/")
assert.Equal(t, expected, parsed)
}
func TestParseCommentMultipleComments(t *testing.T) {
expected := &ParsedComment{
Comment: "/*app:worker-foo*//* another comment*/",
Query: "SELECT * FROM table ORDER BY foo LIMIT 10 OFFSET 10",
}
parsed := parseComment("SELECT * FROM table ORDER BY foo LIMIT 10 OFFSET 10/*app:worker-foo*//* another comment*/")
assert.Equal(t, expected, parsed)
}
func TestParseCommentMultipleCommentsSpace(t *testing.T) {
expected := &ParsedComment{
Comment: "/*app:worker-foo*//* another comment*/",
Query: "SELECT * FROM table ORDER BY foo LIMIT 10 OFFSET 10",
}
parsed := parseComment("SELECT * FROM table ORDER BY foo LIMIT 10 OFFSET 10/*app:worker-foo*/ /* another comment*/")
assert.Equal(t, expected, parsed)
}
func TestParseCommentMultipleCommentsBeforeAndAfter(t *testing.T) {
expected := &ParsedComment{
Comment: "/*app:worker-foo*//* another comment */",
Query: "SELECT * FROM table ORDER BY foo LIMIT 10 OFFSET 10",
}
parsed := parseComment("/*app:worker-foo*/SELECT * FROM table ORDER BY foo LIMIT 10 OFFSET 10/* another comment */")
assert.Equal(t, expected, parsed)
}
func TestIsAgentQueryComment(t *testing.T) {
assert.False(t, isAgentQueryComment(""))
assert.False(t, isAgentQueryComment("foo"))
assert.False(t, isAgentQueryComment("/* app:foo */"))
assert.True(t, isAgentQueryComment("/* app:postgres-monitor-agent */"))
}