-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package util_test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/pganalyze/collector/util" | ||
) | ||
|
||
var isUtilTests = []struct { | ||
input string | ||
expected []bool | ||
expectErr bool | ||
}{ | ||
{ | ||
"SELECT 1", | ||
[]bool{false}, | ||
false, | ||
}, | ||
{ | ||
"INSERT INTO my_table VALUES(123)", | ||
[]bool{false}, | ||
false, | ||
}, | ||
{ | ||
"UPDATE my_table SET foo = 123", | ||
[]bool{false}, | ||
false, | ||
}, | ||
{ | ||
"DELETE FROM my_table", | ||
[]bool{false}, | ||
false, | ||
}, | ||
{ | ||
"SHOW fsync", | ||
[]bool{true}, | ||
false, | ||
}, | ||
{ | ||
"SET fsync = off", | ||
[]bool{true}, | ||
false, | ||
}, | ||
{ | ||
"SELECT 1; SELECT 2;", | ||
[]bool{false, false}, | ||
false, | ||
}, | ||
{ | ||
"SELECT 1; SHOW fsync;", | ||
[]bool{false, true}, | ||
false, | ||
}, | ||
{ | ||
"totally not valid sql", | ||
nil, | ||
true, | ||
}, | ||
} | ||
|
||
func TestIsUtilityStmt(t *testing.T) { | ||
for _, test := range isUtilTests { | ||
actual, err := util.IsUtilityStmt(test.input) | ||
if (err != nil) != test.expectErr { | ||
t.Errorf("IsUtilityStmt(%s): expected err: %t; actual: %s", test.input, test.expectErr, err) | ||
} | ||
if !reflect.DeepEqual(actual, test.expected) { | ||
t.Errorf("IsUtilityStmt(%s): expected %v; actual %v", test.input, test.expected, actual) | ||
} | ||
} | ||
} |