Skip to content

Commit aa7edb1

Browse files
committed
Tests.
1 parent 3484bda commit aa7edb1

File tree

5 files changed

+60
-10
lines changed

5 files changed

+60
-10
lines changed

gormlite/download.sh

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ set -euo pipefail
33

44
cd -P -- "$(dirname -- "$0")"
55

6-
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.5/ddlmod.go"
7-
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.5/ddlmod_test.go"
8-
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.5/error_translator.go"
9-
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.5/migrator.go"
10-
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.5/sqlite.go"
11-
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.5/sqlite_test.go"
6+
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.6/ddlmod.go"
7+
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.6/ddlmod_test.go"
8+
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.6/error_translator.go"
9+
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.6/migrator.go"
10+
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.6/sqlite.go"
11+
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.6/sqlite_test.go"
12+
curl -#OL "https://github.com/go-gorm/sqlite/raw/v1.5.6/sqlite_test.go"
13+
curl -#L "https://github.com/glebarez/sqlite/raw/v1.11.0/sqlite_error_translator_test.go" > error_translator_test.go

gormlite/error_translator_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package gormlite
2+
3+
import (
4+
"testing"
5+
6+
"gorm.io/gorm"
7+
"gorm.io/gorm/logger"
8+
)
9+
10+
func TestErrorTranslator(t *testing.T) {
11+
// This is the DSN of the in-memory SQLite database for these tests.
12+
const InMemoryDSN = "file:testdatabase?mode=memory&cache=shared"
13+
14+
// This is the example object for testing the unique constraint error
15+
type Article struct {
16+
ArticleNumber string `gorm:"unique"`
17+
}
18+
19+
db, err := gorm.Open(Open(InMemoryDSN), &gorm.Config{
20+
Logger: logger.Default.LogMode(logger.Silent),
21+
TranslateError: true})
22+
23+
if err != nil {
24+
t.Errorf("Expected Open to succeed; got error: %v", err)
25+
}
26+
if db == nil {
27+
t.Errorf("Expected db to be non-nil.")
28+
}
29+
30+
err = db.AutoMigrate(&Article{})
31+
if err != nil {
32+
t.Errorf("Expected to migrate database models to succeed: %v", err)
33+
}
34+
35+
err = db.Create(&Article{ArticleNumber: "A00000XX"}).Error
36+
if err != nil {
37+
t.Errorf("Expected first create to succeed: %v", err)
38+
}
39+
40+
err = db.Create(&Article{ArticleNumber: "A00000XX"}).Error
41+
if err == nil {
42+
t.Errorf("Expected second create to fail.")
43+
}
44+
45+
if err != gorm.ErrDuplicatedKey {
46+
t.Errorf("Expected error from second create to be gorm.ErrDuplicatedKey: %v", err)
47+
}
48+
}

gormlite/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/ncruces/go-sqlite3/gormlite
33
go 1.21
44

55
require (
6-
github.com/ncruces/go-sqlite3 v0.16.1
6+
github.com/ncruces/go-sqlite3 v0.16.3
77
gorm.io/gorm v1.25.10
88
)
99

gormlite/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
22
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
33
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
44
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
5-
github.com/ncruces/go-sqlite3 v0.16.1 h1:1wHv7s8y+fWK44UIliotJ42ZV41A5T0sjIAqGmnMrkc=
6-
github.com/ncruces/go-sqlite3 v0.16.1/go.mod h1:feFXbBcbLtxNk6XWG1ROt8MS9+E45yCW3G8o4ixIqZ8=
5+
github.com/ncruces/go-sqlite3 v0.16.3 h1:Ky0denOdmAGOoCE6lQlw6GCJNMD8gTikNWe8rpu+Gjc=
6+
github.com/ncruces/go-sqlite3 v0.16.3/go.mod h1:sAU/vQwBmZ2hq5BlW/KTzqRFizL43bv2JQoBLgXhcMI=
77
github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M=
88
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
99
github.com/tetratelabs/wazero v1.7.3 h1:PBH5KVahrt3S2AHgEjKu4u+LlDbbk+nsGE3KLucy6Rw=

sqlite3/vtab.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static int go_vtab_integrity_wrapper(sqlite3_vtab *pVTab, const char *zSchema,
159159
return rc;
160160
}
161161

162-
static int go_vtab_shadown_name_wrapper(const char *zName) { return 1; }
162+
static int go_vtab_shadown_name_wrapper(const char *zName) { return true; }
163163

164164
int sqlite3_create_module_go(sqlite3 *db, const char *zName, int flags,
165165
go_handle handle) {

0 commit comments

Comments
 (0)