-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document rules and expand test coverage for loader and rules
- Loading branch information
1 parent
c274f09
commit 1e011f7
Showing
5 changed files
with
265 additions
and
1 deletion.
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
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
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
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
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,51 @@ | ||
package rules | ||
|
||
import ( | ||
pg_query "github.com/pganalyze/pg_query_go/v4" | ||
"github.com/stretchr/testify/assert" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestNestedTransaction_Process(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
sql string | ||
inTransaction bool | ||
want bool | ||
}{ | ||
{ | ||
name: "transaction BEGIN statement found", | ||
sql: `BEGIN; ALTER TABLE movies ADD COLUMN released_at TIMESTAMP;`, | ||
inTransaction: true, | ||
want: true, | ||
}, | ||
{ | ||
name: "transaction BEGIN statement found but no active transaction context", | ||
sql: `BEGIN; ALTER TABLE movies ADD COLUMN released_at TIMESTAMP;`, | ||
inTransaction: false, | ||
want: true, | ||
}, | ||
{ | ||
name: "no transaction management statements found", | ||
sql: `ALTER TABLE movies ADD COLUMN released_at TIMESTAMP;`, | ||
inTransaction: true, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
r := NestedTransaction{} | ||
var allNodes []*pg_query.Node | ||
for _, statement := range strings.Split(tt.sql, "\n") { | ||
allNodes = append(allNodes, parseStatement(t, statement)) | ||
} | ||
assert.Equal(t, tt.want, r.Process(allNodes[0], allNodes, true)) | ||
}) | ||
} | ||
} |