From 89bd5d4b3636d553a7aa8768e56b4d089c1de697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Mon, 19 Feb 2024 23:20:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20Go=201.22?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 2 +- .github/workflows/codecov.yml | 2 +- .github/workflows/goreleaser.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/test.yml | 2 +- .gitlab-ci.yml | 2 +- config/filesystems.go | 2 +- go.mod | 6 ++--- go.sum | 8 +++--- pkg/captcha/captcha_test.go | 45 ++++++++++++++++++++++++++++++++ 10 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 pkg/captcha/captcha_test.go diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d86631a..127008b4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-go@v5 with: cache: true - go-version: '1.21' + go-version: 'stable' - name: Install dependencies run: go mod tidy - name: Build ${{ matrix.goarch }} diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 25a3d078..9ee8c577 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: 'stable' - name: Install dependencies run: go mod tidy - name: Run tests with coverage diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 6fec72c4..4ad074a3 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: 'stable' - name: Fetch Frontend run: | sudo apt-get install -y curl jq unzip zip diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d3c3dfee..bb4b66d9 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: 'stable' cache: false - name: Lint uses: golangci/golangci-lint-action@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f43c2ccd..d3df7447 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: 'stable' - name: Install dependencies run: sudo apt-get install -y curl jq - name: Set up environment diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d69de30a..11abc51e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: golang:1.22-bookworm +image: golang:bookworm # 在每个任务执行前运行 before_script: diff --git a/config/filesystems.go b/config/filesystems.go index 8a7218b6..c7adbeef 100644 --- a/config/filesystems.go +++ b/config/filesystems.go @@ -20,7 +20,7 @@ func init() { // may even configure multiple disks of the same driver. Defaults have // been set up for each driver as an example of the required values. // - // Supported Drivers: "local" + // Supported Drivers: "local", "custom" "disks": map[string]any{ "local": map[string]any{ "driver": "local", diff --git a/go.mod b/go.mod index e0985990..887f7ac2 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module panel -go 1.21 +go 1.22 require ( github.com/docker/docker v25.0.3+incompatible @@ -43,7 +43,7 @@ require ( github.com/aliyun/alibaba-cloud-sdk-go v1.61.1755 // indirect github.com/andybalholm/brotli v1.1.0 // indirect github.com/aws/aws-sdk-go v1.49.6 // indirect - github.com/bytedance/sonic v1.10.2 // indirect + github.com/bytedance/sonic v1.11.0 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect @@ -192,7 +192,7 @@ require ( go.uber.org/atomic v1.11.0 // indirect go.uber.org/mock v0.4.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/arch v0.6.0 // indirect + golang.org/x/arch v0.7.0 // indirect golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect golang.org/x/image v0.13.0 // indirect golang.org/x/mod v0.14.0 // indirect diff --git a/go.sum b/go.sum index 7ff1451b..b9b429d1 100644 --- a/go.sum +++ b/go.sum @@ -121,8 +121,8 @@ github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= -github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE= -github.com/bytedance/sonic v1.10.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= +github.com/bytedance/sonic v1.11.0 h1:FwNNv6Vu4z2Onf1++LNzxB/QhitD8wuTdpZzMTGITWo= +github.com/bytedance/sonic v1.11.0/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= github.com/cenkalti/backoff/v4 v4.1.2/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= @@ -763,8 +763,8 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.6.0 h1:S0JTfE48HbRj80+4tbvZDYsJ3tGv6BUU3XxyZ7CirAc= -golang.org/x/arch v0.6.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= +golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= diff --git a/pkg/captcha/captcha_test.go b/pkg/captcha/captcha_test.go new file mode 100644 index 00000000..f64ba084 --- /dev/null +++ b/pkg/captcha/captcha_test.go @@ -0,0 +1,45 @@ +package captcha + +import ( + "testing" + "time" + + "github.com/goravel/framework/testing/mock" + testifymock "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +type CaptchaTestSuite struct { + suite.Suite + captcha *Captcha +} + +func TestCaptchaTestSuite(t *testing.T) { + facade := mock.Factory() + mockConfig := facade.Config() + mockConfig.On("GetString", "app.name").Return("HaoZiPanel").Once() + mockConfig.On("GetInt", "captcha.height").Return(80).Once() + mockConfig.On("GetInt", "captcha.width").Return(240).Once() + mockConfig.On("GetInt", "captcha.length").Return(4).Once() + mockConfig.On("Get", "captcha.maxskew").Return(0.7).Once() + mockConfig.On("GetInt", "captcha.dotcount").Return(80).Once() + mockConfig.On("GetInt", "captcha.expire_time").Return(5).Once() + mockConfig.On("GetInt", "captcha.debug_expire_time").Return(10).Once() + mockConfig.On("GetBool", "app.debug").Return(true).Once() + mockCache := facade.Cache() + mockCache.On("Put", testifymock.Anything, testifymock.Anything, time.Minute*time.Duration(10)).Return(nil).Once() + + suite.Run(t, &CaptchaTestSuite{ + captcha: NewCaptcha(), + }) + + mockConfig.AssertExpectations(t) +} + +func (s *CaptchaTestSuite) TestGenerateCaptcha() { + id, base64, err := s.captcha.GenerateCaptcha() + + s.NotEmpty(id) + s.NotEmpty(base64) + s.Nil(err) +}