Skip to content

Commit

Permalink
test: added tests for autocommit setting
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Nov 26, 2024
1 parent 136969f commit f5fffc2
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions go/transactions/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,53 @@ func TestRun(t *testing.T) {
_ = os.WriteFile("../testdata/expected/small-slow-query-transactions.json", []byte(sb.String()), 0o644)
}
}

func TestAutocommitSettings(t *testing.T) {
tests := []struct {
query string
expect bool
}{
{
query: "set autocommit=1",
expect: true,
}, {
query: "set autocommit=0",
expect: false,
}, {
query: "set autocommit=on",
expect: true,
}, {
query: "set autocommit=off",
expect: false,
}, {
query: "set session autocommit=on",
expect: true,
}, {
query: "set session autocommit=off",
expect: false,
}, {
query: "set @@session.autocommit=1",
expect: true,
}, {
query: "set @@session.autocommit=0",
expect: false,
}, {
query: "set global autocommit = 1",
expect: true,
}, {
query: "set global autocommit = 0",
expect: false,
},
}

parser := sqlparser.NewTestParser()
for _, test := range tests {
t.Run(test.query, func(t *testing.T) {
stmt, err := parser.Parse(test.query)
require.NoError(t, err)
set, ok := stmt.(*sqlparser.Set)
require.True(t, ok)
assert.Equal(t, test.expect, getAutocommitStatus(set, false))
})
}
}

0 comments on commit f5fffc2

Please sign in to comment.