Browse Source

add oci8 tests

tags/v0.5.2
Lunny Xiao 5 years ago
parent
commit
1d60053832
6 changed files with 212 additions and 0 deletions
  1. +7
    -0
      oci8.sh
  2. +1
    -0
      oci8/benchmark.bat
  3. +1
    -0
      oci8/benchmark.sh
  4. +1
    -0
      oci8/oci8.bat
  5. +1
    -0
      oci8/oci8.sh
  6. +201
    -0
      oci8/oci8_test.go

+ 7
- 0
oci8.sh View File

@@ -0,0 +1,7 @@
#!/bin/bash
this_file=$(basename $0)
base_dir_len=`expr ${#this_file} - 3`
test_dir=${this_file: 0: `expr $base_dir_len`}
cd $test_dir
./$this_file
cd -

+ 1
- 0
oci8/benchmark.bat View File

@@ -0,0 +1 @@
go test -v -bench=. -run=XXX

+ 1
- 0
oci8/benchmark.sh View File

@@ -0,0 +1 @@
go test -v -bench=. -run=XXX

+ 1
- 0
oci8/oci8.bat View File

@@ -0,0 +1 @@
go test -v -run=TestOci8

+ 1
- 0
oci8/oci8.sh View File

@@ -0,0 +1 @@
go test -v -run=TestOci8

+ 201
- 0
oci8/oci8_test.go View File

@@ -0,0 +1,201 @@
package tests

import (
"database/sql"
"testing"

. ".."
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
_ "github.com/mattn/go-oci8"
)

var connStr string = "system/oracle@192.168.59.103:49161/xe"

func newOci8Engine() (*xorm.Engine, error) {
orm, err := xorm.NewEngine("oci8", connStr)
if err != nil {
return nil, err
}
tables, err := orm.DBMetas()
if err != nil {
return nil, err
}
for _, table := range tables {
_, err = orm.Exec("drop table \"" + table.Name + "\"")
if err != nil {
return nil, err
}
}

return orm, err
}

func newOci8DriverDB() (*sql.DB, error) {
return sql.Open("oci8", connStr)
}

func TestOci8(t *testing.T) {
engine, err := newOci8Engine()
if err != nil {
t.Error(err)
return
}
defer engine.Close()
engine.ShowSQL = ShowTestSql
engine.ShowErr = ShowTestSql
engine.ShowWarn = ShowTestSql
engine.ShowDebug = ShowTestSql

BaseTestAll(engine, t)
UserTest1(engine, t)
BaseTestAllSnakeMapper(engine, t)
BaseTestAll2(engine, t)
BaseTestAll3(engine, t)
}

func TestOci8WithCache(t *testing.T) {
engine, err := newOci8Engine()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewCacher())
defer engine.Close()
engine.ShowSQL = ShowTestSql
engine.ShowErr = ShowTestSql
engine.ShowWarn = ShowTestSql
engine.ShowDebug = ShowTestSql

BaseTestAll(engine, t)
BaseTestAllSnakeMapper(engine, t)
BaseTestAll2(engine, t)
}

func TestOci8SameMapper(t *testing.T) {
engine, err := newOci8Engine()
if err != nil {
t.Error(err)
return
}
defer engine.Close()
engine.SetMapper(core.SameMapper{})
engine.ShowSQL = ShowTestSql
engine.ShowErr = ShowTestSql
engine.ShowWarn = ShowTestSql
engine.ShowDebug = ShowTestSql

BaseTestAll(engine, t)
BaseTestAllSameMapper(engine, t)
BaseTestAll2(engine, t)
BaseTestAll3(engine, t)
}

func TestOci8WithCacheSameMapper(t *testing.T) {
engine, err := newOci8Engine()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewCacher())
defer engine.Close()
engine.SetMapper(core.SameMapper{})
engine.ShowSQL = ShowTestSql
engine.ShowErr = ShowTestSql
engine.ShowWarn = ShowTestSql
engine.ShowDebug = ShowTestSql

BaseTestAll(engine, t)
BaseTestAllSameMapper(engine, t)
BaseTestAll2(engine, t)
}

const (
createTableOci8 = `CREATE TABLE IF NOT EXISTS "big_struct" ("id" SERIAL PRIMARY KEY NOT NULL, "name" VARCHAR(255) NULL, "title" VARCHAR(255) NULL, "age" VARCHAR(255) NULL, "alias" VARCHAR(255) NULL, "nick_name" VARCHAR(255) NULL);`
dropTableOci8 = `DROP TABLE IF EXISTS "big_struct";`
)

func BenchmarkOci8DriverInsert(t *testing.B) {
DoBenchDriver(newOci8DriverDB, createTableOci8, dropTableOci8,
DoBenchDriverInsert, t)
}

func BenchmarkOci8DriverFind(t *testing.B) {
DoBenchDriver(newOci8DriverDB, createTableOci8, dropTableOci8,
DoBenchDriverFind, t)
}

func BenchmarkOci8NoCacheInsert(t *testing.B) {
engine, err := newOci8Engine()

defer engine.Close()
if err != nil {
t.Error(err)
return
}
//engine.ShowSQL = true
DoBenchInsert(engine, t)
}

func BenchmarkOci8NoCacheFind(t *testing.B) {
engine, err := newOci8Engine()

defer engine.Close()
if err != nil {
t.Error(err)
return
}
//engine.ShowSQL = true
DoBenchFind(engine, t)
}

func BenchmarkOci8NoCacheFindPtr(t *testing.B) {
engine, err := newOci8Engine()

defer engine.Close()
if err != nil {
t.Error(err)
return
}
//engine.ShowSQL = true
DoBenchFindPtr(engine, t)
}

func BenchmarkOci8CacheInsert(t *testing.B) {
engine, err := newOci8Engine()

defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewCacher())

DoBenchInsert(engine, t)
}

func BenchmarkOci8CacheFind(t *testing.B) {
engine, err := newOci8Engine()

defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewCacher())

DoBenchFind(engine, t)
}

func BenchmarkOci8CacheFindPtr(t *testing.B) {
engine, err := newOci8Engine()

defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewCacher())

DoBenchFindPtr(engine, t)
}