Skip to content

Commit

Permalink
修复 CI 问题
Browse files Browse the repository at this point in the history
  • Loading branch information
flycash committed Sep 12, 2023
1 parent 42ad6e4 commit 95c3111
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go-fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 22 additions & 2 deletions internal/integration/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion script/integrate_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions script/integration_test_compose.yml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 95c3111

Please sign in to comment.