Skip to content

Commit 6feddbe

Browse files
committed
feat!: rename Passage struct and ctor signature and remove old Error class
1 parent 6445861 commit 6feddbe

6 files changed

+58
-221
lines changed

app_test.go

-30
This file was deleted.

error.go

-42
This file was deleted.

error_test.go

-30
This file was deleted.

app.go passage.go

+5-23
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,18 @@ import (
66
"net/http"
77
)
88

9-
type Passage = App
10-
11-
// Config holds the configuration for the Passage SDK.
12-
//
13-
// Deprecated: will be removed in v2.
14-
type Config struct {
15-
APIKey string
16-
HeaderAuth bool
17-
}
18-
19-
// App is the main struct for the Passage SDK.
20-
//
21-
// Deprecated: will be renamed to `Passage` in v2.
22-
type App struct {
9+
// Passage is the main struct for the Passage SDK.
10+
type Passage struct {
2311
Auth *auth
2412
User *user
2513
}
2614

2715
// New creates a new Passage instance.
28-
//
29-
// Deprecated: Will be replaced with a different signature in v2 -- `New(appID string, apiKey string) (*Passage, error)`.
30-
func New(appID string, config *Config) (*Passage, error) {
31-
if config == nil {
32-
config = &Config{}
33-
}
34-
16+
func New(appID string, apiKey string) (*Passage, error) {
3517
client, err := NewClientWithResponses(
3618
"https://api.passage.id/v1/",
3719
withPassageVersion(),
38-
withAPIKey(config.APIKey),
20+
withAPIKey(apiKey),
3921
)
4022
if err != nil {
4123
return nil, err
@@ -48,7 +30,7 @@ func New(appID string, config *Config) (*Passage, error) {
4830

4931
user := newUser(appID, client)
5032

51-
return &App{
33+
return &Passage{
5234
User: user,
5335
Auth: auth,
5436
}, nil

passage_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import (
55
"fmt"
66
"os"
77
"strings"
8+
"sync"
89
"testing"
910

1011
"github.com/joho/godotenv"
1112
"github.com/passageidentity/passage-go"
1213
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
1315
)
1416

1517
var (
@@ -74,3 +76,22 @@ func passageBadRequestAsserts(t *testing.T, err error, message string) {
7476
assert.Equal(t, "errorCode: invalid_request", splitError[1])
7577
assert.Equal(t, "statusCode: 400", splitError[2])
7678
}
79+
80+
// should be run with the -race flag, i.e. `go test -race -run TestAppJWKSCacheWriteConcurrency`
81+
func TestAppJWKSCacheWriteConcurrency(t *testing.T) {
82+
goRoutineCount := 2
83+
84+
var wg sync.WaitGroup
85+
wg.Add(goRoutineCount)
86+
87+
for i := 0; i < goRoutineCount; i++ {
88+
go func() {
89+
defer wg.Done()
90+
91+
_, err := passage.New(PassageAppID, PassageApiKey)
92+
require.Nil(t, err)
93+
}()
94+
}
95+
96+
wg.Wait()
97+
}

0 commit comments

Comments
 (0)