-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Set up integration tests * Move tests into packages * Add SDK version header
- Loading branch information
1 parent
9a6b2bf
commit ee8d47d
Showing
12 changed files
with
243 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: integration-test | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
go: | ||
- '1.18' | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
cache: true | ||
|
||
- env: | ||
CORBADO_BACKEND_API: ${{ secrets.CORBADO_BACKEND_API }} | ||
CORBADO_PROJECT_ID: ${{ secrets.CORBADO_PROJECT_ID }} | ||
CORBADO_API_SECRET: ${{ secrets.CORBADO_API_SECRET }} | ||
run: go test -tags=integration ./tests/integration/... |
2 changes: 1 addition & 1 deletion
2
.github/workflows/ci_test.yml → .github/workflows/ci_unit_test.yml
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,4 +1,4 @@ | ||
name: test | ||
name: unit-test | ||
|
||
on: | ||
workflow_call: | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build integration | ||
|
||
package emaillink_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/corbado/corbado-go/pkg/sdk/entity/api" | ||
"github.com/corbado/corbado-go/pkg/sdk/util" | ||
"github.com/corbado/corbado-go/tests/integration" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEmailLinkSend(t *testing.T) { | ||
rsp, err := integration.SDK(t).EmailLinks().Send(context.TODO(), api.EmailLinkSendReq{ | ||
Email: integration.CreateRandomTestEmail(t), | ||
Redirect: "https://some.site.com/authenticate", | ||
TemplateName: util.Ptr("default"), | ||
Create: true, | ||
AdditionalPayload: util.Ptr("{}"), | ||
ClientInfo: util.ClientInfo("foobar", "127.0.0.1"), | ||
}) | ||
|
||
require.NoError(t, err) | ||
assert.NotEmpty(t, rsp.Data.EmailLinkID) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//go:build integration | ||
|
||
package project_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/corbado/corbado-go/tests/integration" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestProjectConfigGet(t *testing.T) { | ||
rsp, err := integration.SDK(t).Projects().ConfigGet(context.TODO()) | ||
|
||
require.NoError(t, err) | ||
assert.Equal(t, integration.GetProjectID(t), rsp.Data.ProjectID) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//go:build integration | ||
|
||
package project_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/corbado/corbado-go/pkg/sdk/entity/api" | ||
"github.com/corbado/corbado-go/pkg/sdk/util" | ||
"github.com/corbado/corbado-go/tests/integration" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestProjectConfigUpdate(t *testing.T) { | ||
newName := integration.CreateRandomTestName(t) | ||
err := integration.SDK(t).Projects().ConfigUpdate(context.TODO(), api.ProjectConfigSaveReq{ | ||
ExternalName: util.Ptr(newName), | ||
}) | ||
require.NoError(t, err) | ||
|
||
newCfg, err := integration.SDK(t).Projects().ConfigGet(context.TODO()) | ||
require.NoError(t, err) | ||
assert.Equal(t, newName, newCfg.Data.ExternalName) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:build integration | ||
|
||
package user_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/corbado/corbado-go/pkg/sdk/entity/api" | ||
"github.com/corbado/corbado-go/pkg/sdk/util" | ||
"github.com/corbado/corbado-go/tests/integration" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestUserList(t *testing.T) { | ||
// send email link first so that we have at least one user | ||
_, err := integration.SDK(t).EmailLinks().Send(context.TODO(), api.EmailLinkSendReq{ | ||
Email: integration.CreateRandomTestEmail(t), | ||
Redirect: "https://some.site.com/authenticate", | ||
TemplateName: util.Ptr("default"), | ||
Create: true, | ||
AdditionalPayload: util.Ptr("{}"), | ||
ClientInfo: util.ClientInfo("foobar", "127.0.0.1"), | ||
}) | ||
require.NoError(t, err) | ||
|
||
usersRsp, err := integration.SDK(t).Users().List(context.TODO(), nil) | ||
require.NoError(t, err) | ||
|
||
assert.True(t, len(usersRsp.Data.Users) > 0) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//go:build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"crypto/rand" | ||
"math/big" | ||
"os" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/corbado/corbado-go" | ||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func SDK(t *testing.T) corbado.SDK { | ||
config, err := corbado.NewConfig(GetProjectID(t), GetAPISecret(t)) | ||
require.NoError(t, err) | ||
config.BackendAPI = GetBackendAPI(t) | ||
|
||
sdk, err := corbado.NewSDK(config) | ||
require.NoError(t, err) | ||
|
||
return sdk | ||
} | ||
|
||
func getEnv(t *testing.T, name string) string { | ||
env := os.Getenv(name) | ||
if env == "" { | ||
t.Fatalf("Missing env variable %s", name) | ||
} | ||
|
||
return env | ||
} | ||
|
||
func GetProjectID(t *testing.T) string { | ||
return getEnv(t, "CORBADO_PROJECT_ID") | ||
} | ||
|
||
func GetAPISecret(t *testing.T) string { | ||
return getEnv(t, "CORBADO_API_SECRET") | ||
} | ||
|
||
func GetBackendAPI(t *testing.T) string { | ||
return getEnv(t, "CORBADO_BACKEND_API") | ||
} | ||
|
||
func CreateRandomTestEmail(t *testing.T) string { | ||
value, err := generateString(10) | ||
require.NoError(t, err) | ||
|
||
return getFunctionName() + value + "@test.de" | ||
} | ||
|
||
func CreateRandomTestName(t *testing.T) string { | ||
value, err := generateString(10) | ||
require.NoError(t, err) | ||
|
||
return value | ||
} | ||
|
||
func generateString(length int) (string, error) { | ||
// Removed I, 1, 0 and O because of risk of confusion | ||
const letters = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijklmnopwrstuvwxyz23456789" | ||
|
||
res := make([]byte, length) | ||
for i := 0; i < length; i++ { | ||
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters)))) | ||
if err != nil { | ||
return "", errors.WithStack(err) | ||
} | ||
|
||
res[i] = letters[num.Int64()] | ||
} | ||
|
||
return string(res), nil | ||
} | ||
|
||
func getFunctionName() string { | ||
pc := make([]uintptr, 15) | ||
n := runtime.Callers(3, pc) | ||
|
||
frames := runtime.CallersFrames(pc[:n]) | ||
frame, _ := frames.Next() | ||
|
||
functionName := frame.Function | ||
functionName = functionName[strings.LastIndex(functionName, ".")+1:] | ||
functionName = functionName[5:] | ||
|
||
return functionName | ||
} |