diff --git a/.github/workflows/go-fmt.yml b/.github/workflows/go-fmt.yml index 23f9523b..b255e39d 100644 --- a/.github/workflows/go-fmt.yml +++ b/.github/workflows/go-fmt.yml @@ -24,11 +24,11 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v3 with: - go-version: ">=1.20.0" + go-version: ">=1.21.0" - name: Install goimports run: go install golang.org/x/tools/cmd/goimports@latest diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index aa724fe3..1a00e4e6 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -24,11 +24,11 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v2 with: - go-version: '1.20' + go-version: '1.21' - name: Build run: go build -v ./... diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 30abeff0..9149fbd7 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -33,8 +33,8 @@ jobs: steps: - uses: actions/setup-go@v3 with: - go-version: '1.20' - - uses: actions/checkout@v3 + go-version: '1.21' + - uses: actions/checkout@v4 - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index a8b8f050..446cdc75 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -24,11 +24,11 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v2 with: - go-version: '1.20' + go-version: '1.21' - name: Test run: sudo sh ./script/integrate_test.sh \ No newline at end of file diff --git a/internal/integration/user_test.go b/internal/integration/user_test.go index 0417fb50..0eb6d275 100644 --- a/internal/integration/user_test.go +++ b/internal/integration/user_test.go @@ -12,16 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build e2e + package integration import ( "bytes" + "context" + "database/sql" + "log" "net/http" "net/http/httptest" "testing" "time" - "github.com/ecodeclub/webook/config" "github.com/ecodeclub/webook/internal/repository" "github.com/ecodeclub/webook/internal/repository/dao" "github.com/ecodeclub/webook/internal/service" @@ -176,7 +180,23 @@ func InitTest() *gin.Engine { } func initDB() *gorm.DB { - db, err := gorm.Open(mysql.Open(config.Config.DB.DSN)) + dsn := "root:root@tcp(localhost:13316)/webook" + sqlDB, err := sql.Open("mysql", dsn) + if err != nil { + panic(err) + } + + for { + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + err = sqlDB.PingContext(ctx) + cancel() + if err == nil { + break + } + log.Println("初始化集成测试的 DB", err) + time.Sleep(time.Second) + } + db, err := gorm.Open(mysql.Open(dsn)) if err != nil { panic(err) } diff --git a/script/integrate_test.sh b/script/integrate_test.sh index 1eae897b..aebe962f 100644 --- a/script/integrate_test.sh +++ b/script/integrate_test.sh @@ -3,6 +3,5 @@ set -e docker compose -f script/integration_test_compose.yml down docker compose -f script/integration_test_compose.yml up -d -echo "127.0.0.1 slave.a.com" >> /etc/hosts go test -race ./... -tags=e2e docker compose -f script/integration_test_compose.yml down diff --git a/script/integration_test_compose.yml b/script/integration_test_compose.yml index 57af8630..30f1d49d 100644 --- a/script/integration_test_compose.yml +++ b/script/integration_test_compose.yml @@ -1,14 +1,13 @@ version: "3" services: - mysql8: - image: mysql:8.0.25 + image: mysql:8.0 command: --default_authentication_plugin=mysql_native_password environment: MYSQL_ROOT_PASSWORD: root volumes: # 设置初始化脚本 - - ./script/mysql/user.sql:docker-entrypoint-initdb.d + - ./mysql/user.sql:/docker-entrypoint-initdb.d/init.sql ports: # 映射 13316端口 - "13316:3306"