Skip to content

Commit ea28c24

Browse files
committed
Test for rowcount
1 parent 517e77b commit ea28c24

5 files changed

Lines changed: 44 additions & 5 deletions

File tree

migrations/0001.sqlcode.sql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,4 @@ grant execute on sqlcode.CreateCodeSchema to [sqlcode-deploy-role];
132132
grant execute on sqlcode.DropCodeSchema to [sqlcode-deploy-role];
133133
grant create procedure to [sqlcode-deploy-role];
134134
grant create function to [sqlcode-deploy-role];
135-
grant create type to [sqlcode-deploy-role];
136-
137-
138-
alter user
135+
grant create type to [sqlcode-deploy-role];

migrations/0002.sqlcode.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- We want to re-create the procedure DropCodeSchema.
2-
-- Frist, everything related to this procedure must be dropped
2+
-- First, everything related to this procedure must be dropped
33
-- before it is re-created in the end.
44

55
drop procedure sqlcode.DropCodeSchema;

sqltest/sql.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package sqltest
2+
3+
import (
4+
"embed"
5+
6+
"github.com/vippsas/sqlcode"
7+
)
8+
9+
//go:embed *.sql
10+
var sqlfs embed.FS
11+
12+
var SQL = sqlcode.MustInclude(
13+
sqlcode.Options{},
14+
sqlfs,
15+
)

sqltest/sqlcode_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package sqltest
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func Test_RowsAffected(t *testing.T) {
11+
fixture := NewFixture()
12+
defer fixture.Teardown()
13+
fixture.RunMigrationFile("../migrations/0001.sqlcode.sql")
14+
15+
ctx := context.Background()
16+
17+
require.NoError(t, SQL.EnsureUploaded(ctx, fixture.DB))
18+
patched := SQL.Patch(`select [code].Test`)
19+
20+
res, err := fixture.DB.ExecContext(ctx, patched)
21+
require.NoError(t, err)
22+
println(res.RowsAffected())
23+
}

sqltest/test.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
create procedure [code].Test as
2+
begin
3+
select 1
4+
end

0 commit comments

Comments
 (0)