From 6ac3304c342a95bcf4c1b2cc3dd05d5efe22221c Mon Sep 17 00:00:00 2001 From: icpd <35096485+icpd@users.noreply.github.com> Date: Thu, 8 Aug 2024 16:55:44 +0800 Subject: [PATCH] Refactor test setup and dependency management This commit primarily focuses on the reorganization of test files and modification of module dependencies. The test files have been relocated to the 'tests' directory for clearer structure. Additionally, module dependencies relevant for testing have been updated to reflect current requirements. Simultaneously, the PostgreSQL setup has been removed from the GitHub Actions workflow, simplifying the Continuous Integration setup. --- .github/workflows/go.yml | 22 +-------------------- go.mod | 9 ++------- go.sum | 25 ++++-------------------- tests/go.mod | 18 +++++++++++++++++ tests/go.sum | 12 ++++++++++++ version_test.go => tests/version_test.go | 3 ++- 6 files changed, 39 insertions(+), 50 deletions(-) create mode 100644 tests/go.mod create mode 100644 tests/go.sum rename version_test.go => tests/version_test.go (99%) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d61e29f..33f618e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -3,27 +3,6 @@ on: [push,pull_request] jobs: test: runs-on: ubuntu-latest - # Service containers to run with `container-job` - services: - # Label used to access the service container - postgres: - # Docker Hub image - image: postgres - # Provide the password for postgres - env: - POSTGRES_USER: gorm - POSTGRES_PASSWORD: gorm - POSTGRES_PORT: 5432 - TZ: Asia/Shanghai - # Set health checks to wait until postgres has started - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - # Maps tcp port 5432 on service container to the host - - 9920:5432 steps: - name: Get latest go version id: version @@ -46,4 +25,5 @@ jobs: ${{ runner.os }}-go- - name: Get dependencies, run test run: | + cd tests go test ./... diff --git a/go.mod b/go.mod index 7abdc56..b9fe64e 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,10 @@ module gorm.io/plugin/optimisticlock -go 1.17 +go 1.18 -require ( - gorm.io/driver/sqlite v1.2.6 - gorm.io/gorm v1.23.8 -) +require gorm.io/gorm v1.25.11 require ( github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect - github.com/mattn/go-sqlite3 v1.14.9 // indirect - gopkg.in/yaml.v3 v3.0.0 // indirect ) diff --git a/go.sum b/go.sum index da11db1..72406eb 100644 --- a/go.sum +++ b/go.sum @@ -1,25 +1,8 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/mattn/go-sqlite3 v1.14.9 h1:10HX2Td0ocZpYEjhilsuo6WWtUqttj2Kb0KtD86/KYA= -github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/sqlite v1.2.6 h1:SStaH/b+280M7C8vXeZLz/zo9cLQmIGwwj3cSj7p6l4= -gorm.io/driver/sqlite v1.2.6/go.mod h1:gyoX0vHiiwi0g49tv+x2E7l8ksauLK0U/gShcdUsjWY= -gorm.io/gorm v1.22.3/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0= -gorm.io/gorm v1.23.8 h1:h8sGJ+biDgBA1AD1Ha9gFCx7h8npU7AsLdlkX0n2TpE= -gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= +gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= diff --git a/tests/go.mod b/tests/go.mod new file mode 100644 index 0000000..55193f4 --- /dev/null +++ b/tests/go.mod @@ -0,0 +1,18 @@ +module gorm.io/plugin/optimisticlock/tests + +go 1.18 + +require ( + gorm.io/driver/sqlite v1.5.6 + gorm.io/gorm v1.25.11 + gorm.io/plugin/optimisticlock v1.1.3 +) + +require ( + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/mattn/go-sqlite3 v1.14.22 // indirect + golang.org/x/text v0.14.0 // indirect +) + +replace gorm.io/plugin/optimisticlock => ../ diff --git a/tests/go.sum b/tests/go.sum new file mode 100644 index 0000000..33c59d5 --- /dev/null +++ b/tests/go.sum @@ -0,0 +1,12 @@ +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= +github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +gorm.io/driver/sqlite v1.5.6 h1:fO/X46qn5NUEEOZtnjJRWRzZMe8nqJiQ9E+0hi+hKQE= +gorm.io/driver/sqlite v1.5.6/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4= +gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= +gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= diff --git a/version_test.go b/tests/version_test.go similarity index 99% rename from version_test.go rename to tests/version_test.go index 07d529d..4afb34c 100644 --- a/version_test.go +++ b/tests/version_test.go @@ -1,4 +1,4 @@ -package optimisticlock +package tests import ( "database/sql/driver" @@ -10,6 +10,7 @@ import ( "gorm.io/driver/sqlite" "gorm.io/gorm" + . "gorm.io/plugin/optimisticlock" ) type User struct {