Skip to content

Commit 124d075

Browse files
committed
Renew Session 支持
1 parent e012fac commit 124d075

File tree

17 files changed

+447
-105
lines changed

17 files changed

+447
-105
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,5 @@ jobs:
3333
- name: Build
3434
run: go build -v ./...
3535

36-
- name: Test
37-
run: go test -race -coverprofile=cover.out -v ./...
38-
39-
- name: Post Coverage
40-
uses: codecov/codecov-action@v2
36+
- name: Unit Test
37+
run: go test -race -v ./...

.github/workflows/integration_test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ jobs:
3131
go-version: '1.21.1'
3232

3333
- name: Test
34-
run: make e2e
34+
run: make e2e
35+
36+
- name: Post Coverage
37+
uses: codecov/codecov-action@v2

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@
2020
# Go workspace file
2121
go.work
2222

23-
.idea
23+
.idea
24+
*.out
25+
.run

.script/integrate_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
set -e
1818
docker compose -f .script/integration_test_compose.yml down
1919
docker compose -f .script/integration_test_compose.yml up -d
20-
go test ./... -tags=e2e
20+
go test -race -coverprofile=cover.out -tags=e2e ./...
2121
docker compose -f .script/integration_test_compose.yml down

internal/integration/activelimit_test.go renamed to internal/e2e/activelimit_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
//go:build e2e
1616

17-
package integration
17+
package e2e
1818

1919
import (
2020
"context"
@@ -25,19 +25,13 @@ import (
2525
"time"
2626

2727
"github.com/ecodeclub/ginx/middlewares/activelimit/redislimit"
28-
"github.com/redis/go-redis/v9"
29-
3028
"github.com/gin-gonic/gin"
3129
"github.com/stretchr/testify/assert"
3230
"github.com/stretchr/testify/require"
3331
)
3432

3533
func TestBuilder_e2e_ActiveRedisLimit(t *testing.T) {
36-
redisClient := redis.NewClient(&redis.Options{
37-
Addr: "localhost:16379",
38-
Password: "",
39-
DB: 0,
40-
})
34+
redisClient := newRedisTestClient()
4135
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
4236
defer cancel()
4337
err := redisClient.Ping(ctx).Err()

internal/e2e/base_suite.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2023 ecodeclub
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build e2e
16+
17+
package e2e
18+
19+
import (
20+
"github.com/redis/go-redis/v9"
21+
"github.com/stretchr/testify/suite"
22+
)
23+
24+
type BaseSuite struct {
25+
suite.Suite
26+
RDB redis.Cmdable
27+
}
28+
29+
func (s *BaseSuite) SetupSuite() {
30+
s.RDB = newRedisTestClient()
31+
}
32+
33+
func (s *BaseSuite) TearDownSuite() {
34+
if s.RDB != nil {
35+
s.RDB.(*redis.Client).Close()
36+
}
37+
}

internal/e2e/dependency.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2023 ecodeclub
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build e2e
16+
17+
package e2e
18+
19+
import "github.com/redis/go-redis/v9"
20+
21+
var redisCfg = &redis.Options{
22+
Addr: "localhost:16379",
23+
Password: "",
24+
DB: 0,
25+
}
26+
27+
func newRedisTestClient() *redis.Client {
28+
return redis.NewClient(redisCfg)
29+
}

internal/e2e/gin_writer.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2023 ecodeclub
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package e2e
16+
17+
import (
18+
"bufio"
19+
"net"
20+
"net/http"
21+
)
22+
23+
type GinResponseWriter struct {
24+
http.ResponseWriter
25+
}
26+
27+
func (g *GinResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
28+
panic("implement me")
29+
}
30+
31+
func (g *GinResponseWriter) Flush() {
32+
panic("implement me")
33+
}
34+
35+
func (g *GinResponseWriter) CloseNotify() <-chan bool {
36+
panic("implement me")
37+
}
38+
39+
func (g *GinResponseWriter) Status() int {
40+
panic("implement me")
41+
}
42+
43+
func (g *GinResponseWriter) Size() int {
44+
panic("implement me")
45+
}
46+
47+
func (g *GinResponseWriter) WriteString(s string) (int, error) {
48+
panic("implement me")
49+
}
50+
51+
func (g *GinResponseWriter) Written() bool {
52+
panic("implement me")
53+
}
54+
55+
func (g *GinResponseWriter) WriteHeaderNow() {
56+
panic("implement me")
57+
}
58+
59+
func (g *GinResponseWriter) Pusher() http.Pusher {
60+
panic("implement me")
61+
}

internal/integration/ratelimit_test.go renamed to internal/e2e/ratelimit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
//go:build e2e
1616

17-
package integration
17+
package e2e
1818

1919
import (
2020
"context"

session/global.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ func SetDefaultProvider(sp Provider) {
4545
func CheckLoginMiddleware() gin.HandlerFunc {
4646
return (&MiddlewareBuilder{sp: defaultProvider}).Build()
4747
}
48+
49+
func RenewAccessToken(ctx *gctx.Context) error {
50+
return defaultProvider.RenewAccessToken(ctx)
51+
}

0 commit comments

Comments
 (0)