-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: removes e2e tests in favor of the sdk-test suite (#131)
- Loading branch information
Showing
5 changed files
with
2 additions
and
508 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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) | ||
}() | ||
} | ||
|
Oops, something went wrong.