Skip to content

Commit

Permalink
add more testing files
Browse files Browse the repository at this point in the history
  • Loading branch information
sijms committed May 10, 2024
1 parent 6c7cc4d commit 4a248bb
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 0 deletions.
2 changes: 2 additions & 0 deletions v2/TestIssues/global_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func init() {
urlOptions["SSL VERIFY"] = "false"
urlOptions["wallet"] = wallet
}
urlOptions["DATA INTEGRITY"] = "required"
urlOptions["ENCRYPTION"] = "required"
}

func execCmd(db *sql.DB, stmts ...string) error {
Expand Down
25 changes: 25 additions & 0 deletions v2/TestIssues/issue_486_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package TestIssues

import "testing"

func TestIssue486(t *testing.T) {
db, err := getDB()
if err != nil {
t.Error(err)
return
}
defer func() {
err = db.Close()
if err != nil {
t.Error(err)
}
}()
var value string
err = db.QueryRow("SELECT 'AAA안녕하세요' FROM dual").Scan(&value)
if err != nil {
t.Error(err)
}
if value != "AAA안녕하세요" {
t.Errorf("expected %s and got %s", "AAA안녕하세요", value)
}
}
81 changes: 81 additions & 0 deletions v2/TestIssues/issue_532_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package TestIssues

import (
"database/sql"
"strconv"
"testing"
)

func TestIssue532(t *testing.T) {
type TTB_DATA struct {
ID int `db:"ID"`
Name string `db:"NAME"`
}
var createTable = func(db *sql.DB) error {
return execCmd(db, `CREATE TABLE TTB_532(
EMP_ID NUMBER,
EMP_NAME VARCHAR2(255),
PRIMARY KEY (EMP_ID)
)`)
}

var dropTable = func(db *sql.DB) error {
return execCmd(db, "drop table TTB_532 purge")
}

var insert = func(db *sql.DB, rowNum int) error {
data := make([]TTB_DATA, rowNum)
for index := range data {
data[index].ID = index + 1
data[index].Name = "NAME_" + strconv.Itoa(index+1)
}
_, err := db.Exec(`INSERT INTO TTB_532(EMP_ID, EMP_NAME) VALUES(:ID, :NAME)`, data)
return err
}

var query = func(db *sql.DB) error {
rows, err := db.Query("SELECT * FROM TTB_532 FOR UPDATE")
if err != nil {
return err
}
defer func() {
err = rows.Close()
if err != nil {
t.Error(err)
}
}()
return nil
}
db, err := getDB()
if err != nil {
t.Error(err)
return
}
defer func() {
err = db.Close()
if err != nil {
t.Error(err)
}
}()
err = createTable(db)
if err != nil {
t.Error(err)
return
}
defer func() {
err = dropTable(db)
if err != nil {
t.Error(err)
}
}()
err = insert(db, 7)
if err != nil {
t.Error(err)
return
}
err = query(db)
if err != nil {
t.Error(err)
return
}
}
29 changes: 29 additions & 0 deletions v2/TestIssues/issue_543_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package TestIssues

import (
"testing"
)

func TestIssue543(t *testing.T) {
expected := "CASE WHEN \"SESSION_ID\" IS NULL THEN \"SECURITY_GROUP_ID\" END "
db, err := getDB()
if err != nil {
t.Error(err)
return
}
defer func() {
err = db.Close()
if err != nil {
t.Error(err)
}
}()
var result string
err = db.QueryRow("select column_expression from dba_ind_expressions where index_owner = 'APEX_230200' and index_name = 'WWV_FLOW_WORKSHEET_RPTS_UK' and column_position = 1").Scan(&result)
if err != nil {
t.Error(err)
return
}
if result != expected {
t.Errorf("expected: %s and got: %s", expected, result)
}
}
101 changes: 101 additions & 0 deletions v2/TestIssues/large_udt_array_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package TestIssues

import (
"database/sql"
go_ora "github.com/sijms/go-ora/v2"
"testing"
)

func TestLargeUDTArray(t *testing.T) {
var createTypes = func(db *sql.DB) error {
return execCmd(db, `
create or replace type stringsType as object(
STRING1 varchar2(60),
STRING2 varchar2(300)
)`, `create or replace type stringsTypeCol as table of stringsType`)
}
var dropTypes = func(db *sql.DB) error {
return execCmd(db, "DROP TYPE stringsTypeCol", "DROP TYPE stringsType")
}
type StringsType struct {
String1 string `udt:"STRING1"`
String2 string `udt:"STRING2"`
}
var inputPars = func(db *sql.DB, input []StringsType) (int, error) {
var length int
_, err := db.Exec(`
DECLARE
inp stringsTypeCol;
BEGIN
inp := :1;
:2 := inp.count;
END;`, input, go_ora.Out{Dest: &length})
return length, err
}
var outputPars = func(db *sql.DB, length int) ([]StringsType, error) {
var output []StringsType
_, err := db.Exec(`
declare
outp stringsTypeCol;
ext number;
begin
ext := :1;
outp := stringsTypeCol();
outp.extend(ext);
for n in 1..ext
loop
outp(n) := stringsType('string1','string2');
end loop;
:2 := outp;
end;
`, length, go_ora.Out{Dest: &output})
return output, err
}
db, err := getDB()
if err != nil {
t.Error(err)
return
}
defer func() {
err = db.Close()
if err != nil {
t.Error(err)
}
}()
err = createTypes(db)
if err != nil {
t.Error(err)
return
}
defer func() {
err = dropTypes(db)
if err != nil {
t.Error(err)
}
}()
err = go_ora.RegisterType(db, "stringsType", "stringsTypeCol", StringsType{})
if err != nil {
t.Error(err)
return
}
size := 0x200
output, err := inputPars(db, make([]StringsType, size))
if err != nil {
t.Error(err)
return
}
if output != size {
t.Errorf("expected size: %d and got: %d", size, output)
return
}
outputArray, err := outputPars(db, size)
if err != nil {
t.Error(err)
return
}
if len(outputArray) != size {
t.Errorf("expected size: %d and got: %d", size, len(outputArray))
}

}

0 comments on commit 4a248bb

Please sign in to comment.