diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 6052baa6..42d7b012 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -1,6 +1,7 @@ name: Go on: + workflow_call: push: branches: - master @@ -8,11 +9,14 @@ on: env: TEST_RESULTS: /tmp/test-results # path to where test results will be saved - GH_ACTIONS: "1" + GH_ACTIONS: "0" + TEST_SKIP_COMMENTS: "1" + GO_VERSION: "1.22.5" jobs: - test: + initialize_data: + name: Initialize Test Data runs-on: ubuntu-latest steps: - name: Checkout Repository @@ -22,47 +26,107 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.21.6" + go-version: ${{ env.GO_VERSION }} - name: Verify go version run: go version - - name: Install GoTest - run: go install gotest.tools/gotestsum@latest -# - name: Install jet generator -# run: cd tests && make install-jet-gen - name: Init database run: | cd tests - go run ./init/init.go -testsuite all - # to create test results report - - name: Install go-junit-report - run: go install github.com/jstemmer/go-junit-report@latest - - name: Setup Test Report Dir - run: mkdir -p $TEST_RESULTS - # this will run all tests and exclude test files from code coverage report - - name: Run Tests - run: | - go test -v ./... \ - -covermode=atomic \ - -coverpkg=github.com/go-jet/jet/v2/postgres/...,github.com/go-jet/jet/v2/mysql/...,github.com/go-jet/jet/v2/sqlite/...,github.com/go-jet/jet/v2/qrm/...,github.com/go-jet/jet/v2/generator/...,github.com/go-jet/jet/v2/internal/... \ - -coverprofile=cover.out 2>&1 | go-junit-report > $TEST_RESULTS/results.xml - - # run mariaDB and cockroachdb tests. No need to collect coverage, because coverage is already included with mysql and postgres tests - - name: Run MariaDB tests - run: MY_SQL_SOURCE=MariaDB go test -v ./tests/mysql/ - - name: Run cockroach DB - run: PG_SOURCE=COCKROACH_DB go test -v ./tests/postgres/ - - name: Archive code coverage results - uses: actions/upload-artifact@v4 + go run ./init/init.go -testsuite mysql + go run ./init/init.go -testsuite mariadb + # go run ./init/init.go -testsuite all + - uses: actions/upload-artifact@v4 + with: + name: testData + include-hidden-files: true + path: ${{ github.workspace }}/tests/.gentestdata/ +# standard_tests: +# name: Run Standard Tests +# needs: initialize_data +# runs-on: ubuntu-latest +# steps: +# - name: Checkout Repository +# uses: actions/checkout@v4 +# with: +# submodules: 'true' +# - name: Set up Go +# uses: actions/setup-go@v5 +# with: +# go-version: ${{ env.GO_VERSION }} +# - uses: actions/download-artifact@v4 +# with: +# name: testData +# path: ./tests/.gentestdata +# # to create test results report +# - name: Install go-junit-report +# run: go install github.com/jstemmer/go-junit-report/v2@latest +# - name: locate binary +# run: which go-junit-report +# - name: Install jet +# run: go install ./cmd/jet +# - name: Setup Test Report Dir +# run: mkdir -p ${{ env.TEST_RESULTS }} +# # this will run all tests and exclude test files from code coverage report +# - name: Run Tests +# run: | +# go test -v ./... \ +# -covermode=atomic \ +# -coverpkg=github.com/go-jet/jet/v2/postgres/...,github.com/go-jet/jet/v2/mysql/...,github.com/go-jet/jet/v2/sqlite/...,github.com/go-jet/jet/v2/qrm/...,github.com/go-jet/jet/v2/generator/...,github.com/go-jet/jet/v2/internal/... \ +# -coverprofile=cover.out 2>&1 | go-junit-report > ${{ env.TEST_RESULTS }}/results.xml +# - name: Archive code coverage results +# uses: actions/upload-artifact@v4 +# with: +# name: code-coverage-report +# path: ${{ env.TEST_RESULTS }}/results.xml +# - name: Store cover.out +# uses: actions/upload-artifact@v4 +# with: +# name: cover.out +# path: cover.out +# - name: Store test-results +# uses: actions/upload-artifact@v4 +# with: +# name: test-results +# path: /tmp/test-results +# cockroach_test: +# name: Cockroach Test +# needs: initialize_data +# runs-on: ubuntu-latest +# steps: +# - name: Checkout Repository +# uses: actions/checkout@v4 +# with: +# submodules: 'true' +# - name: Set up Go +# uses: actions/setup-go@v5 +# with: +# go-version: ${{ env.GO_VERSION }} +# - uses: actions/download-artifact@v4 +# with: +# name: testData +# path: ./tests/.gentestdata +# - name: Install jet +# run: go install ./cmd/jet +# - name: Run cockroach DB +# run: PG_SOURCE=COCKROACH_DB go test -v ./tests/postgres/ + maria_test: + name: MariaDB Test + needs: initialize_data + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 with: - name: code-coverage-report - path: $TEST_RESULTS/results.xml - - name: Store cover.out - uses: actions/upload-artifact@v4 + submodules: 'true' + - name: Set up Go + uses: actions/setup-go@v5 with: - name: cover.out - path: cover.out - - name: Store test-results - uses: actions/upload-artifact@v4 + go-version: ${{ env.GO_VERSION }} + - uses: actions/download-artifact@v4 with: - name: test-results - path: /tmp/test-results \ No newline at end of file + name: testData + path: ./tests/.gentestdata + - name: Install jet + run: go install ./cmd/jet + - name: Run MariaDB tests + run: MY_SQL_SOURCE=MariaDB go test -v ./tests/mysql/ \ No newline at end of file diff --git a/internal/testutils/test_utils.go b/internal/testutils/test_utils.go index 22c0d9ce..a045a2ab 100644 --- a/internal/testutils/test_utils.go +++ b/internal/testutils/test_utils.go @@ -109,7 +109,7 @@ func SaveJSONFile(v interface{}, testRelativePath string) { jsonText, _ := json.MarshalIndent(v, "", "\t") filePath := getFullPath(testRelativePath) - err := ioutil.WriteFile(filePath, jsonText, 0644) + err := os.WriteFile(filePath, jsonText, 0644) throw.OnError(err) } diff --git a/tests/init/init.go b/tests/init/init.go index 31a0ab3d..30520f36 100644 --- a/tests/init/init.go +++ b/tests/init/init.go @@ -78,15 +78,15 @@ func main() { return initSQLiteDB() }) case "all": - err = timeMethod("postgres Schema Generation complete", func() error { - return initPostgresDB(Postgres) + err = timeMethod("couchDB Schema Generation complete", func() error { + return initPostgresDB(Cockroach) }) if err != nil { break } - err = timeMethod("couchDB Schema Generation complete", func() error { - return initPostgresDB(Cockroach) + err = timeMethod("postgres Schema Generation complete", func() error { + return initPostgresDB(Postgres) }) if err != nil { break diff --git a/tests/internal/utils/common/const.go b/tests/internal/utils/common/const.go index 4e45e91e..b9a12ad0 100644 --- a/tests/internal/utils/common/const.go +++ b/tests/internal/utils/common/const.go @@ -3,7 +3,8 @@ package common import "os" const ( - GhActions = "GH_ACTIONS" + GhActions = "GH_ACTIONS" + GhSkipComments = "TEST_SKIP_COMMENTS" ) func IsCICDTest() bool { @@ -12,5 +13,6 @@ func IsCICDTest() bool { // Add a hack to bypass failing tests func IsHack() bool { - return true + return os.Getenv(GhSkipComments) == "1" + //return true } diff --git a/tests/mysql/generator_test.go b/tests/mysql/generator_test.go index ba61b5b0..3aa13e44 100644 --- a/tests/mysql/generator_test.go +++ b/tests/mysql/generator_test.go @@ -76,9 +76,6 @@ func TestGenerator_TableMetadata(t *testing.T) { } func TestCmdGenerator(t *testing.T) { - if common.IsCICDTest() { - t.SkipNow() - } err := os.RemoveAll(genTestDir3) require.NoError(t, err) @@ -127,9 +124,6 @@ func TestCmdGenerator(t *testing.T) { } func TestIgnoreTablesViewsEnums(t *testing.T) { - if common.IsCICDTest() { - t.SkipNow() - } tests := []struct { name string args []string diff --git a/tests/postgres/generator_test.go b/tests/postgres/generator_test.go index dd2332e4..fe1308ce 100644 --- a/tests/postgres/generator_test.go +++ b/tests/postgres/generator_test.go @@ -2,7 +2,6 @@ package postgres import ( "fmt" - "github.com/go-jet/jet/v2/tests/internal/utils/common" "os" "os/exec" "path/filepath" @@ -85,9 +84,6 @@ func getEnvironmentPort() string { func TestCmdGenerator(t *testing.T) { skipForCockroachDB(t) - if common.IsCICDTest() { - t.SkipNow() - } err := os.RemoveAll(genTestDir2) require.NoError(t, err) @@ -124,9 +120,6 @@ func TestCmdGenerator(t *testing.T) { } func TestGeneratorIgnoreTables(t *testing.T) { - if common.IsCICDTest() { - t.SkipNow() - } skipForCockroachDB(t) tests := []struct { name string diff --git a/tests/sqlite/generator_test.go b/tests/sqlite/generator_test.go index 129ec4fb..8a155680 100644 --- a/tests/sqlite/generator_test.go +++ b/tests/sqlite/generator_test.go @@ -1,7 +1,6 @@ package sqlite import ( - "github.com/go-jet/jet/v2/tests/internal/utils/common" "os" "os/exec" "reflect" @@ -93,9 +92,6 @@ func TestGenerator_TableMetadata(t *testing.T) { } func TestCmdGenerator(t *testing.T) { - if common.IsCICDTest() { - t.SkipNow() - } cmd := exec.Command("jet", "-source=SQLite", "-dsn=file://"+testDatabaseFilePath, "-path="+genDestDir) cmd.Stderr = os.Stderr @@ -111,9 +107,6 @@ func TestCmdGenerator(t *testing.T) { } func TestCmdGeneratorIgnoreTablesViewsEnums(t *testing.T) { - if common.IsCICDTest() { - t.SkipNow() - } cmd := exec.Command("jet", "-source=SQLite", "-dsn=file://"+testDatabaseFilePath,