Skip to content

Commit

Permalink
test: removes e2e tests in favor of the sdk-test suite (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctran88 authored Jan 28, 2025
1 parent 5ef9833 commit 5755802
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 508 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ on:
workflow_dispatch:
pull_request:

env:
PASSAGE_APP_ID: ${{ secrets.PASSAGE_APP_ID }}
PASSAGE_API_KEY: ${{ secrets.PASSAGE_API_KEY }}
PASSAGE_USER_ID: ${{ secrets.PASSAGE_USER_ID }}
PASSAGE_AUTH_TOKEN: ${{ secrets.PASSAGE_AUTH_TOKEN }}

jobs:
lint:
name: Lint
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.21

require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/joho/godotenv v1.5.1
github.com/lestrrat-go/jwx/v2 v2.1.3
github.com/oapi-codegen/runtime v1.1.1
github.com/stretchr/testify v1.10.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keL
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N+AkAr5k=
github.com/lestrrat-go/blackmagic v1.0.2/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU=
Expand Down
72 changes: 2 additions & 70 deletions passage_test.go
Original file line number Diff line number Diff line change
@@ -1,82 +1,13 @@
package passage_test

import (
"crypto/rand"
"fmt"
"os"
"strings"
"sync"
"testing"

"github.com/joho/godotenv"
"github.com/passageidentity/passage-go/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var (
PassageAppID string
PassageApiKey string
PassageUserID string
PassageAuthToken string
RandomEmail = generateRandomEmail(14)
CreatedUser passage.PassageUser
)

func generateRandomEmail(prefixLength int) string {
n := prefixLength
randomChars := make([]byte, n)
if _, err := rand.Read(randomChars); err != nil {
panic(err)
}
email := fmt.Sprintf("%[email protected]", randomChars)
return strings.ToLower(email)
}

func TestMain(m *testing.M) {
_ = godotenv.Load(".env")

PassageAppID = os.Getenv("PASSAGE_APP_ID")
PassageApiKey = os.Getenv("PASSAGE_API_KEY")
PassageUserID = os.Getenv("PASSAGE_USER_ID")
PassageAuthToken = os.Getenv("PASSAGE_AUTH_TOKEN")

exitVal := m.Run()
os.Exit(exitVal)
}

func passageUserNotFoundAsserts(t *testing.T, err error) {
splitError := strings.Split(err.Error(), ", ")
assert.Len(t, splitError, 3)
assert.Equal(t, "PassageError - message: User not found", splitError[0])
assert.Equal(t, "errorCode: user_not_found", splitError[1])
assert.Equal(t, "statusCode: 404", splitError[2])
}

func passageCouldNotFindUserByIdentifierAsserts(t *testing.T, err error) {
splitError := strings.Split(err.Error(), ", ")
assert.Len(t, splitError, 3)
assert.Equal(t, "PassageError - message: Could not find user with that identifier.", splitError[0])
assert.Equal(t, "errorCode: user_not_found", splitError[1])
assert.Equal(t, "statusCode: 404", splitError[2])
}

func passageUnauthorizedAsserts(t *testing.T, err error) {
splitError := strings.Split(err.Error(), ", ")
assert.Len(t, splitError, 3)
assert.Equal(t, "PassageError - message: Invalid access token", splitError[0])
assert.Equal(t, "errorCode: invalid_access_token", splitError[1])
assert.Equal(t, "statusCode: 401", splitError[2])
}

func passageBadRequestAsserts(t *testing.T, err error, message string) {
splitError := strings.Split(err.Error(), ", ")
assert.Len(t, splitError, 3)
assert.Equal(t, "PassageError - message: "+message, splitError[0])
assert.Equal(t, "errorCode: invalid_request", splitError[1])
assert.Equal(t, "statusCode: 400", splitError[2])
}

// should be run with the -race flag, i.e. `go test -race -run TestAppJWKSCacheWriteConcurrency`
func TestAppJWKSCacheWriteConcurrency(t *testing.T) {
goRoutineCount := 2
Expand All @@ -88,7 +19,8 @@ func TestAppJWKSCacheWriteConcurrency(t *testing.T) {
go func() {
defer wg.Done()

_, err := passage.New(PassageAppID, PassageApiKey)
// a network call is made upon initialization to retrieve the JWKs from a real source
_, err := passage.New("passage", "some-api-key")
require.Nil(t, err)
}()
}
Expand Down
Loading

0 comments on commit 5755802

Please sign in to comment.