Skip to content

Commit 8aef2a7

Browse files
committed
Fixed readme and gc test
1 parent fc149e3 commit 8aef2a7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ The store accepts an adapter interface that interacts with the DB. Adapter and i
1818
package main
1919

2020
import (
21+
"context"
2122
"os"
2223
"time"
2324

24-
"github.com/jackc/pgx"
25+
"github.com/jackc/pgx/v4"
2526
pg "github.com/vgarvardt/go-oauth2-pg"
26-
"github.com/vgarvardt/go-pg-adapter/pgxadapter"
27+
"github.com/vgarvardt/go-pg-adapter/pgx4adapter"
2728
"gopkg.in/oauth2.v3/manage"
2829
)
2930

3031
func main() {
31-
pgxConnConfig, _ := pgx.ParseURI(os.Getenv("DB_URI"))
32-
pgxConn, _ := pgx.Connect(pgxConnConfig)
32+
pgxConn, _ := pgx.Connect(context.TODO(), os.Getenv("DB_URI"))
3333

3434
manager := manage.NewDefaultManager()
3535

3636
// use PostgreSQL token store with pgx.Connection adapter
37-
adapter := pgxadapter.NewConn(pgxConn)
37+
adapter := pgx4adapter.NewConn(pgxConn)
3838
tokenStore, _ := pg.NewTokenStore(adapter, pg.WithTokenStoreGCInterval(time.Minute))
3939
defer tokenStore.Close()
4040

token_store_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ func TestTokenStore_initTable(t *testing.T) {
9595
func TestTokenStore_gc(t *testing.T) {
9696
adapter := new(mockAdapter)
9797

98+
var execCalls int
9899
adapter.On("Exec", mock.Anything, mock.Anything, mock.Anything).Return(nil).Run(func(args mock.Arguments) {
100+
execCalls++
101+
99102
query := args.Get(1).(string)
100103
// new line character is the character at position 0
101104
assert.Equal(t, 0, strings.Index(query, "DELETE FROM"))
@@ -111,7 +114,8 @@ func TestTokenStore_gc(t *testing.T) {
111114
time.Sleep(5 * time.Second)
112115

113116
// in 5 seconds we should have 4-5 gc calls
114-
adapter.AssertNumberOfCalls(t, "Exec", 4)
117+
assert.True(t, 3 < execCalls)
118+
assert.True(t, 5 >= execCalls)
115119
}
116120

117121
func generateTokenTableName() string {

0 commit comments

Comments
 (0)