Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renew Session 支持 #18

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,5 @@ jobs:
- name: Build
run: go build -v ./...

- name: Test
run: go test -race -coverprofile=cover.out -v ./...

- name: Post Coverage
uses: codecov/codecov-action@v2
- name: Unit Test
run: go test -race -v ./...
5 changes: 4 additions & 1 deletion .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ jobs:
go-version: '1.21.1'

- name: Test
run: make e2e
run: make e2e

- name: Post Coverage
uses: codecov/codecov-action@v2
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
# Go workspace file
go.work

.idea
.idea
*.out
.run
2 changes: 1 addition & 1 deletion .script/integrate_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
set -e
docker compose -f .script/integration_test_compose.yml down
docker compose -f .script/integration_test_compose.yml up -d
go test ./... -tags=e2e
go test -race -coverprofile=cover.out -tags=e2e ./...
docker compose -f .script/integration_test_compose.yml down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

//go:build e2e

package integration
package e2e

import (
"context"
Expand All @@ -25,19 +25,13 @@ import (
"time"

"github.com/ecodeclub/ginx/middlewares/activelimit/redislimit"
"github.com/redis/go-redis/v9"

"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestBuilder_e2e_ActiveRedisLimit(t *testing.T) {
redisClient := redis.NewClient(&redis.Options{
Addr: "localhost:16379",
Password: "",
DB: 0,
})
redisClient := newRedisTestClient()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()
err := redisClient.Ping(ctx).Err()
Expand Down Expand Up @@ -160,6 +154,7 @@ func TestBuilder_e2e_ActiveRedisLimit(t *testing.T) {
time.Sleep(time.Millisecond * 100)
redisClient.Del(context.Background(), tc.key)
fmt.Println(redisClient.Get(context.Background(), tc.key).Int64())
tc := tc
t.Run(tc.name, func(t *testing.T) {

server := gin.Default()
Expand Down
37 changes: 37 additions & 0 deletions internal/e2e/base_suite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2023 ecodeclub
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build e2e

package e2e

import (
"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/suite"
)

type BaseSuite struct {
suite.Suite
RDB redis.Cmdable
}

func (s *BaseSuite) SetupSuite() {
s.RDB = newRedisTestClient()

Check warning on line 30 in internal/e2e/base_suite.go

View check run for this annotation

Codecov / codecov/patch

internal/e2e/base_suite.go#L29-L30

Added lines #L29 - L30 were not covered by tests
}

func (s *BaseSuite) TearDownSuite() {
if s.RDB != nil {
s.RDB.(*redis.Client).Close()
}

Check warning on line 36 in internal/e2e/base_suite.go

View check run for this annotation

Codecov / codecov/patch

internal/e2e/base_suite.go#L33-L36

Added lines #L33 - L36 were not covered by tests
}
29 changes: 29 additions & 0 deletions internal/e2e/dependency.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2023 ecodeclub
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build e2e

package e2e

import "github.com/redis/go-redis/v9"

var redisCfg = &redis.Options{
Addr: "localhost:16379",
Password: "",
DB: 0,
}

func newRedisTestClient() *redis.Client {
return redis.NewClient(redisCfg)
}
61 changes: 61 additions & 0 deletions internal/e2e/gin_writer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2023 ecodeclub
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package e2e

import (
"bufio"
"net"
"net/http"
)

type GinResponseWriter struct {
http.ResponseWriter
}

func (g *GinResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
panic("implement me")

Check warning on line 28 in internal/e2e/gin_writer.go

View check run for this annotation

Codecov / codecov/patch

internal/e2e/gin_writer.go#L27-L28

Added lines #L27 - L28 were not covered by tests
}

func (g *GinResponseWriter) Flush() {
panic("implement me")

Check warning on line 32 in internal/e2e/gin_writer.go

View check run for this annotation

Codecov / codecov/patch

internal/e2e/gin_writer.go#L31-L32

Added lines #L31 - L32 were not covered by tests
}

func (g *GinResponseWriter) CloseNotify() <-chan bool {
panic("implement me")

Check warning on line 36 in internal/e2e/gin_writer.go

View check run for this annotation

Codecov / codecov/patch

internal/e2e/gin_writer.go#L35-L36

Added lines #L35 - L36 were not covered by tests
}

func (g *GinResponseWriter) Status() int {
panic("implement me")

Check warning on line 40 in internal/e2e/gin_writer.go

View check run for this annotation

Codecov / codecov/patch

internal/e2e/gin_writer.go#L39-L40

Added lines #L39 - L40 were not covered by tests
}

func (g *GinResponseWriter) Size() int {
panic("implement me")

Check warning on line 44 in internal/e2e/gin_writer.go

View check run for this annotation

Codecov / codecov/patch

internal/e2e/gin_writer.go#L43-L44

Added lines #L43 - L44 were not covered by tests
}

func (g *GinResponseWriter) WriteString(s string) (int, error) {
panic("implement me")

Check warning on line 48 in internal/e2e/gin_writer.go

View check run for this annotation

Codecov / codecov/patch

internal/e2e/gin_writer.go#L47-L48

Added lines #L47 - L48 were not covered by tests
}

func (g *GinResponseWriter) Written() bool {
panic("implement me")

Check warning on line 52 in internal/e2e/gin_writer.go

View check run for this annotation

Codecov / codecov/patch

internal/e2e/gin_writer.go#L51-L52

Added lines #L51 - L52 were not covered by tests
}

func (g *GinResponseWriter) WriteHeaderNow() {
panic("implement me")

Check warning on line 56 in internal/e2e/gin_writer.go

View check run for this annotation

Codecov / codecov/patch

internal/e2e/gin_writer.go#L55-L56

Added lines #L55 - L56 were not covered by tests
}

func (g *GinResponseWriter) Pusher() http.Pusher {
panic("implement me")

Check warning on line 60 in internal/e2e/gin_writer.go

View check run for this annotation

Codecov / codecov/patch

internal/e2e/gin_writer.go#L59-L60

Added lines #L59 - L60 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

//go:build e2e

package integration
package e2e

import (
"context"
Expand Down
4 changes: 4 additions & 0 deletions session/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@
func CheckLoginMiddleware() gin.HandlerFunc {
return (&MiddlewareBuilder{sp: defaultProvider}).Build()
}

func RenewAccessToken(ctx *gctx.Context) error {
return defaultProvider.RenewAccessToken(ctx)

Check warning on line 50 in session/global.go

View check run for this annotation

Codecov / codecov/patch

session/global.go#L49-L50

Added lines #L49 - L50 were not covered by tests
}
11 changes: 11 additions & 0 deletions session/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@
"github.com/ecodeclub/ginx/internal/errs"
)

var _ Session = &MemorySession{}

// MemorySession 一般用于测试
type MemorySession struct {
data map[string]any
claims Claims
}

func (m *MemorySession) Destroy(ctx context.Context) error {
return nil

Check warning on line 33 in session/memory.go

View check run for this annotation

Codecov / codecov/patch

session/memory.go#L32-L33

Added lines #L32 - L33 were not covered by tests
}

func (m *MemorySession) Del(ctx context.Context, key string) error {
delete(m.data, key)
return nil

Check warning on line 38 in session/memory.go

View check run for this annotation

Codecov / codecov/patch

session/memory.go#L36-L38

Added lines #L36 - L38 were not covered by tests
}

func NewMemorySession(cl Claims) *MemorySession {
return &MemorySession{
data: map[string]any{},
Expand Down
42 changes: 42 additions & 0 deletions session/provider.mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading