Skip to content

Commit eb42a0b

Browse files
rafaelbramp
authored andcommitted
Added tests
Signed-off-by: Rafael Chacon <rafael@slack-corp.com>
1 parent 4a0dad5 commit eb42a0b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

comments.go

+1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func (d CommentDirectives) IsSet(key string) bool {
261261
return false
262262
}
263263

264+
// SkipQueryPlanCacheDirective returns true if skip query plan cache directive is set to true in query.
264265
func SkipQueryPlanCacheDirective(stmt Statement) (skipQuerPlanCacheDirective bool) {
265266
switch stmt := stmt.(type) {
266267
case *Select:

comments_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,30 @@ func TestExtractCommentDirectives(t *testing.T) {
346346
t.Errorf("d.IsSet(six) should be false")
347347
}
348348
}
349+
350+
func TestSkipQueryPlanCacheDirective(t *testing.T) {
351+
stmt, _ := Parse("insert /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ into user(id) values (1), (2)")
352+
if !SkipQueryPlanCacheDirective(stmt) {
353+
t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true")
354+
}
355+
356+
stmt, _ = Parse("insert into user(id) values (1), (2)")
357+
if SkipQueryPlanCacheDirective(stmt) {
358+
t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be false")
359+
}
360+
361+
stmt, _ = Parse("update /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ users set name=1")
362+
if !SkipQueryPlanCacheDirective(stmt) {
363+
t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true")
364+
}
365+
366+
stmt, _ = Parse("select /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ * from users")
367+
if !SkipQueryPlanCacheDirective(stmt) {
368+
t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true")
369+
}
370+
371+
stmt, _ = Parse("delete /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ from users")
372+
if !SkipQueryPlanCacheDirective(stmt) {
373+
t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true")
374+
}
375+
}

0 commit comments

Comments
 (0)