From 658d47173ab51561accde84216455a4b93f5858c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Garcia?= Date: Tue, 29 Oct 2024 22:49:34 -0300 Subject: [PATCH 1/4] Try to fix CI --- .github/workflows/ci.yml | 2 +- benchmarks/go.sum | 1 - go.mod | 9 ++------- go.sum | 11 +++++++++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0069e17..ad10868 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.21' + go-version: '>=1.23' - uses: actions/checkout@v3 - name: Pull Postgres diff --git a/benchmarks/go.sum b/benchmarks/go.sum index a420695..c10089a 100644 --- a/benchmarks/go.sum +++ b/benchmarks/go.sum @@ -465,7 +465,6 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= diff --git a/go.mod b/go.mod index dab9005..317c022 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,10 @@ module github.com/vingarcia/ksql -go 1.22 +go 1.14 -toolchain go1.22.1 - -require github.com/stretchr/testify v1.9.0 +require github.com/stretchr/testify v1.8.1 require ( - github.com/davecgh/go-spew v1.1.1 // indirect github.com/kr/pretty v0.3.0 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 8f51ef5..a3adf27 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,5 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -13,12 +14,18 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 4352f659c182122840d8f9ee4db18c55c9a96406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Garcia?= Date: Tue, 29 Oct 2024 23:06:40 -0300 Subject: [PATCH 2/4] Add logs to debug --- test_adapters.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test_adapters.go b/test_adapters.go index 37d5a89..79b9f8d 100644 --- a/test_adapters.go +++ b/test_adapters.go @@ -796,6 +796,7 @@ func InsertTest( }, } + ctx = InjectLogger(ctx, Logger) err := c.Insert(ctx, NewTable("users", "name"), &u) tt.AssertNoErr(t, err) tt.AssertEqual(t, u.Name, "FernandaIsTheID") From 31dfbeca3fec925133885b111f9c72d21b5ec200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Garcia?= Date: Wed, 30 Oct 2024 08:49:11 -0300 Subject: [PATCH 3/4] Fix test that was not working on sqlserver (for good reasons) --- benchmarks/sqlcgen/db.go | 2 +- benchmarks/sqlcgen/models.go | 4 +++- benchmarks/sqlcgen/queries.sql.go | 2 +- test_adapters.go | 8 +++++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/benchmarks/sqlcgen/db.go b/benchmarks/sqlcgen/db.go index af38f8d..7f34027 100644 --- a/benchmarks/sqlcgen/db.go +++ b/benchmarks/sqlcgen/db.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.14.0 package sqlcgen diff --git a/benchmarks/sqlcgen/models.go b/benchmarks/sqlcgen/models.go index f108b31..4c83f97 100644 --- a/benchmarks/sqlcgen/models.go +++ b/benchmarks/sqlcgen/models.go @@ -1,9 +1,11 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.14.0 package sqlcgen +import () + type User struct { ID int32 Name string diff --git a/benchmarks/sqlcgen/queries.sql.go b/benchmarks/sqlcgen/queries.sql.go index 50dc904..aba4a14 100644 --- a/benchmarks/sqlcgen/queries.sql.go +++ b/benchmarks/sqlcgen/queries.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.14.0 // source: queries.sql package sqlcgen diff --git a/test_adapters.go b/test_adapters.go index 79b9f8d..f904fa4 100644 --- a/test_adapters.go +++ b/test_adapters.go @@ -789,11 +789,17 @@ func InsertTest( t.Run("should insert one user correctly with a string ID", func(t *testing.T) { c := newTestDB(db, dialect) - u := user{ + type strIDUser struct { + Name string `ksql:"name"` + Age int `ksql:"age"` + Address address `ksql:"address,json"` + } + u := strIDUser{ Name: "FernandaIsTheID", Address: address{ Country: "Brazil", }, + Age: 42, } ctx = InjectLogger(ctx, Logger) From be21a807501e4245c8e99d6f0005dad696baacf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Garcia?= Date: Wed, 30 Oct 2024 09:08:25 -0300 Subject: [PATCH 4/4] Add test to try to fix the test coverage issue --- adapters/ksqlserver/ksqlserver_test.go | 3 +++ ksql.go | 2 +- test_adapters.go | 22 +++++++++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/adapters/ksqlserver/ksqlserver_test.go b/adapters/ksqlserver/ksqlserver_test.go index b4a3de7..75698ea 100644 --- a/adapters/ksqlserver/ksqlserver_test.go +++ b/adapters/ksqlserver/ksqlserver_test.go @@ -76,6 +76,9 @@ func startSQLServerDB(dbName string) (databaseURL string, closer func()) { } sqlDB.Close() + // SQLServer keeps failing frequently, lets try to wait a little before returning: + time.Sleep(500 * time.Millisecond) + return databaseUrl, func() { if err := pool.Purge(resource); err != nil { fmt.Printf("Could not purge resource: %s\n", err) diff --git a/ksql.go b/ksql.go index dbb49d0..5ab6ce4 100644 --- a/ksql.go +++ b/ksql.go @@ -548,7 +548,7 @@ func (c DB) insertWithLastInsertID( fallthrough default: return fmt.Errorf( - "can't convert last insert id of type int64 into field `%s` of type %v", + "error scanning field `%s` cannot assign last insert id of type int64 into field of type %v", idName, fieldType, ) diff --git a/test_adapters.go b/test_adapters.go index f904fa4..52f6452 100644 --- a/test_adapters.go +++ b/test_adapters.go @@ -802,7 +802,6 @@ func InsertTest( Age: 42, } - ctx = InjectLogger(ctx, Logger) err := c.Insert(ctx, NewTable("users", "name"), &u) tt.AssertNoErr(t, err) tt.AssertEqual(t, u.Name, "FernandaIsTheID") @@ -1073,6 +1072,27 @@ func InsertTest( t.Fatal("could not create test table!, reason:", err.Error()) } + t.Run("should report error if the attribute used to retrieve the ID is not supported ", func(t *testing.T) { + c := newTestDB(db, dialect) + + type invalidIDUser struct { + ID struct{} `ksql:"id"` + Name string `ksql:"name"` + Age int `ksql:"age"` + Address address `ksql:"address,json"` + } + u := invalidIDUser{ + Name: "Mauro", + Address: address{ + Country: "Brazil", + }, + Age: 42, + } + + err := c.Insert(ctx, usersTable, &u) + tt.AssertErrContains(t, err, "error", "scanning", "into", "struct {}") + }) + t.Run("should report error for invalid input types", func(t *testing.T) { c := newTestDB(db, dialect)