forked from CengSin/oracle
-
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.
- Loading branch information
Showing
5 changed files
with
201 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
|
||
test: | ||
name: test | ||
runs-on: ubuntu-latest | ||
container: | ||
image: ghcr.io/moveaxlab/oracle-devcontainer:latest | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
- name: get dependencies | ||
run: go mod download | ||
- name: Test | ||
continue-on-error: true | ||
run: go test -v ./... |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[tools] | ||
go = "1.22" | ||
go = "1.21" |
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 |
---|---|---|
@@ -1,19 +1,23 @@ | ||
module github.com/cengsin/oracle | ||
|
||
go 1.22 | ||
go 1.21 | ||
|
||
require ( | ||
github.com/emirpasic/gods v1.18.1 | ||
github.com/godror/godror v0.42.1 | ||
github.com/stretchr/testify v1.9.0 | ||
github.com/thoas/go-funk v0.9.3 | ||
gorm.io/gorm v1.25.9 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/go-logfmt/logfmt v0.6.0 // indirect | ||
github.com/godror/knownpb v0.1.1 // indirect | ||
github.com/jinzhu/inflection v1.0.0 // indirect | ||
github.com/jinzhu/now v1.1.5 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 // indirect | ||
google.golang.org/protobuf v1.33.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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,167 @@ | ||
package oracle | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
"gorm.io/gorm" | ||
"gorm.io/gorm/clause" | ||
"gorm.io/gorm/logger" | ||
) | ||
|
||
type Model struct { | ||
Id int `gorm:"column:ID"` | ||
Name string `gorm:"column:NAME"` | ||
} | ||
|
||
func (Model) TableName() string { | ||
return "TEST_TABLE" | ||
} | ||
|
||
type OracleSuite struct { | ||
suite.Suite | ||
|
||
db *gorm.DB | ||
} | ||
|
||
func (s *OracleSuite) TearDownTest() { | ||
err := s.db.Exec("DELETE FROM TEST_TABLE WHERE 1 = 1").Error | ||
s.Require().Nil(err) | ||
} | ||
|
||
func (s *OracleSuite) TearDownSuite() { | ||
err := s.db.Exec("DROP TABLE TEST_TABLE").Error | ||
s.Require().Nil(err) | ||
} | ||
|
||
type Oracle19Suite struct { | ||
OracleSuite | ||
} | ||
|
||
func (s *Oracle19Suite) SetupSuite() { | ||
url := BuildUrl("oracle-19c", 1521, "MYATP", "ADMIN", "TVDGXvpzQat8", map[string]string{ | ||
"CONNECTION TIMEOUT": "5", | ||
"LANGUAGE": "ITALIAN", | ||
"TERRITORY": "ITALY", | ||
"SSL": "false", | ||
}) | ||
|
||
dialector := New(Config{DSN: url}) | ||
|
||
var err error | ||
|
||
s.db, err = gorm.Open(dialector, &gorm.Config{ | ||
SkipDefaultTransaction: true, | ||
PrepareStmt: false, | ||
Logger: logger.Default.LogMode(logger.Info), | ||
}) | ||
s.Require().Nil(err) | ||
|
||
err = s.db.Exec("CREATE TABLE TEST_TABLE (ID INT PRIMARY KEY, NAME VARCHAR2(64 CHAR) NOT NULL)").Error | ||
s.Require().Nil(err) | ||
} | ||
|
||
type Oracle23Suite struct { | ||
OracleSuite | ||
} | ||
|
||
func (s *Oracle23Suite) SetupSuite() { | ||
url := BuildUrl("oracle-23c", 1521, "FREE", "SYSTEM", "password", map[string]string{ | ||
"CONNECTION TIMEOUT": "5", | ||
"LANGUAGE": "ITALIAN", | ||
"TERRITORY": "ITALY", | ||
"SSL": "false", | ||
}) | ||
|
||
dialector := New(Config{DSN: url}) | ||
|
||
var err error | ||
|
||
logger.Default.LogMode(logger.Info) | ||
|
||
s.db, err = gorm.Open(dialector, &gorm.Config{ | ||
SkipDefaultTransaction: true, | ||
PrepareStmt: false, | ||
Logger: logger.Default.LogMode(logger.Info), | ||
}) | ||
s.Require().Nil(err) | ||
|
||
err = s.db.Exec("CREATE TABLE TEST_TABLE (ID INT PRIMARY KEY, NAME VARCHAR2(64 CHAR) NOT NULL)").Error | ||
s.Require().Nil(err) | ||
} | ||
|
||
func TestOracle19c(t *testing.T) { | ||
suite.Run(t, new(Oracle19Suite)) | ||
} | ||
|
||
func TestOracle23c(t *testing.T) { | ||
suite.Run(t, new(Oracle23Suite)) | ||
} | ||
|
||
func (s *OracleSuite) TestEntityFound() { | ||
var err error | ||
|
||
err = s.db.Create(&Model{ | ||
Id: 1, | ||
Name: "test", | ||
}).Error | ||
s.Require().Nil(err) | ||
|
||
var m Model | ||
|
||
err = s.db. | ||
Where("id = ?", 1). | ||
First(&m). | ||
Error | ||
|
||
s.Require().Nil(err) | ||
} | ||
|
||
func (s *OracleSuite) TestEntityNotFound() { | ||
var err error | ||
|
||
var m Model | ||
|
||
err = s.db. | ||
Where("id = ?", 2). | ||
First(&m). | ||
Error | ||
|
||
s.Require().ErrorIs(err, gorm.ErrRecordNotFound) | ||
} | ||
|
||
func (s *OracleSuite) TestEntityFoundForUpdate() { | ||
var err error | ||
|
||
err = s.db.Create(&Model{ | ||
Id: 1, | ||
Name: "test", | ||
}).Error | ||
s.Require().Nil(err) | ||
|
||
var m Model | ||
|
||
err = s.db.Transaction(func(tx *gorm.DB) error { | ||
return tx. | ||
Clauses(clause.Locking{Strength: "UPDATE"}). | ||
Where("id = ?", 1). | ||
First(&m). | ||
Error | ||
}) | ||
s.Require().Nil(err) | ||
} | ||
|
||
func (s *OracleSuite) TestEntityNotFoundForUpdate() { | ||
var err error | ||
|
||
var m Model | ||
|
||
err = s.db.Transaction(func(tx *gorm.DB) error { | ||
return tx. | ||
Clauses(clause.Locking{Strength: "UPDATE"}). | ||
Where("id = ?", 2). | ||
First(&m). | ||
Error | ||
}) | ||
s.Require().ErrorIs(err, gorm.ErrRecordNotFound) | ||
} |