From f99aa2f504b47a506ec9af1f9908f259a3fb7c3b Mon Sep 17 00:00:00 2001 From: Steve Fan <29133953+stevefan1999-personal@users.noreply.github.com> Date: Mon, 31 Aug 2020 01:42:28 +0800 Subject: [PATCH] add oracle related stuff --- .github/workflows/tests.yml | 30 ++++++++++++++++++++++++++++++ tests/go.mod | 1 + tests/tests_all.sh | 20 +++++++++++++++++++- tests/tests_test.go | 7 +++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4388c31d..5cdfd24d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -189,3 +189,33 @@ jobs: - name: Tests run: GORM_DIALECT=sqlserver GORM_DSN="sqlserver://gorm:LoremIpsum86@localhost:9930?database=gorm" ./tests/tests_all.sh + oracle: + needs: sqlite + strategy: + matrix: + go: ['1.15', '1.14', '1.13'] + platform: [ubuntu-latest] # can not run test in macOS and windows + runs-on: ${{ matrix.platform }} + + services: + oracle: + image: stevefan1999/docker-oracle-xe:latest + ports: + - 9940:1521 + steps: + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: go mod pakcage cache + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('go.mod') }} + + - name: Tests + run: GORM_ENABLE_CACHE=true GORM_DIALECT=oracle GORM_DSN="gorm/gorm@localhost:9940/XEPDB1" ./tests/tests_all.sh \ No newline at end of file diff --git a/tests/go.mod b/tests/go.mod index c09747ab..356a9262 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -6,6 +6,7 @@ require ( github.com/google/uuid v1.1.1 github.com/jinzhu/now v1.1.1 github.com/lib/pq v1.6.0 + github.com/stevefan1999-personal/gorm-driver-oracle v0.0.0-20200830154622-da7a71b7196d gorm.io/driver/mysql v1.0.0 gorm.io/driver/postgres v1.0.0 gorm.io/driver/sqlite v1.1.0 diff --git a/tests/tests_all.sh b/tests/tests_all.sh index e87ff045..59fa4881 100755 --- a/tests/tests_all.sh +++ b/tests/tests_all.sh @@ -1,6 +1,9 @@ #!/bin/bash -e -dialects=("sqlite" "mysql" "postgres" "sqlserver") +dialects=("sqlite" "mysql" "postgres" "sqlserver" "oracle") + +ORACLE_INSTANT_CLIENT_URL="https://download.oracle.com/otn_software/linux/instantclient/19600/instantclient-basic-linux.x64-19.6.0.0.0dbru.zip" +ORACLE_INSTANT_CLIENT_FILE="instant_client.zip" if [[ $(pwd) == *"gorm/tests"* ]]; then cd .. @@ -17,6 +20,21 @@ fi for dialect in "${dialects[@]}" ; do if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ] then + if [[ "$dialect" =~ "oracle" ]] + then + if [[ ! -d $(pwd)/instantclient_19_6 ]] + then + if [[ ! -f "$ORACLE_INSTANT_CLIENT_FILE" ]] + then + echo "downloading oracle instant client..." + curl "$ORACLE_INSTANT_CLIENT_URL" -o "$ORACLE_INSTANT_CLIENT_FILE" + fi + echo "unzipping oracle instant client..." + unzip -o "$ORACLE_INSTANT_CLIENT_FILE" + fi + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/instantclient_19_6 + echo "exported instant client libraries to LD_LIBRARY_PATH, now it should not complain about missing oracle libraries" + fi echo "testing ${dialect}..." if [ "$GORM_VERBOSE" = "" ] diff --git a/tests/tests_test.go b/tests/tests_test.go index 192160a0..d71c15af 100644 --- a/tests/tests_test.go +++ b/tests/tests_test.go @@ -7,6 +7,7 @@ import ( "path/filepath" "time" + "github.com/stevefan1999-personal/gorm-driver-oracle" "gorm.io/driver/mysql" "gorm.io/driver/postgres" "gorm.io/driver/sqlite" @@ -71,6 +72,12 @@ func OpenTestConnection() (db *gorm.DB, err error) { dbDSN = "sqlserver://gorm:LoremIpsum86@localhost:9930?database=gorm" } db, err = gorm.Open(sqlserver.Open(dbDSN), &gorm.Config{}) + case "oracle": + log.Println("testing oracle...") + if dbDSN == "" { + dbDSN = "gorm/gorm@localhost:9940/XEPDB1" + } + db, err = gorm.Open(oracle.Open(dbDSN), &gorm.Config{}) default: log.Println("testing sqlite3...") db, err = gorm.Open(sqlite.Open(filepath.Join(os.TempDir(), "gorm.db")), &gorm.Config{})