-
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.
- Loading branch information
Showing
9 changed files
with
273 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: tests | ||
run-name: tests, branch:${{ github.ref_name }}, triggered by @${{ github.actor }} | ||
|
||
concurrency: | ||
# Run only for most recent commit in PRs but for all tags and commits on main | ||
# Ref: https://docs.github.com/en/actions/using-jobs/using-concurrency | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- '*' | ||
push: | ||
branches: | ||
- 'main' | ||
schedule: | ||
- cron: '30 2 * * *' | ||
workflow_dispatch: {} | ||
|
||
jobs: | ||
unit-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod | ||
|
||
- name: run unit tests | ||
run: make test.unit | ||
|
||
integration-tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- konnect-api-url: https://us.api.konghq.tech | ||
- konnect-api-url: https://eu.api.konghq.tech | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod | ||
|
||
- name: run integration tests | ||
run: make test.integration | ||
env: | ||
KONNECT_API_URL: ${{ matrix.konnect-api-url }} | ||
KONNECT_API_PAT: ${{ secrets.KONNECT_API_PAT }} |
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,4 +1,14 @@ | ||
github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= | ||
github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 h1:S92OBrGuLLZsyM5ybUzgc/mPjIYk2AZqufieooe98uw= | ||
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= | ||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,82 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdkkonnectcomp "github.com/Kong/sdk-konnect-go/models/components" | ||
sdkkonnectops "github.com/Kong/sdk-konnect-go/models/operations" | ||
) | ||
|
||
func TestControlPlaneCreateDelete(t *testing.T) { | ||
t.Parallel() | ||
|
||
sdk := SDK(t) | ||
runID := KonnectTestRunID(t) | ||
|
||
ctx := context.Background() | ||
req := sdkkonnectcomp.CreateControlPlaneRequest{ | ||
Name: NamePrefix(t) + "-" + runID, | ||
Labels: Labels(t), | ||
} | ||
resp, err := sdk.ControlPlanes.CreateControlPlane(ctx, req) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { | ||
_, err := sdk.ControlPlanes.DeleteControlPlane(ctx, resp.ControlPlane.ID) | ||
require.NoError(t, err) | ||
}) | ||
|
||
require.NotNil(t, resp) | ||
require.NotEmpty(t, resp.ControlPlane.ID) | ||
require.NotEmpty(t, resp.ControlPlane.Name) | ||
require.NotNil(t, resp.ControlPlane.Labels) | ||
require.EqualValues(t, Labels(t), resp.ControlPlane.Labels) | ||
} | ||
|
||
func TestControlPlaneList(t *testing.T) { | ||
t.Parallel() | ||
|
||
sdk := SDK(t) | ||
|
||
ctx := context.Background() | ||
reqList := sdkkonnectops.ListControlPlanesRequest{ | ||
// TODO listing doesn't work with criteria yet. | ||
} | ||
respList, err := sdk.ControlPlanes.ListControlPlanes(ctx, reqList) | ||
require.NoError(t, err) | ||
require.NotNil(t, respList.ListControlPlanesResponse) | ||
|
||
// TODO listing doesn't work with criteria yet. | ||
|
||
// require.Empty(t, respList.ListControlPlanesResponse.Data) | ||
|
||
// req := sdkkonnectcomp.CreateControlPlaneRequest{ | ||
// Name: cpName, | ||
// Labels: Labels(t), | ||
// } | ||
// resp, err := sdk.ControlPlanes.CreateControlPlane(ctx, req) | ||
// require.NoError(t, err) | ||
// t.Cleanup(func() { | ||
// _, err := sdk.ControlPlanes.DeleteControlPlane(ctx, resp.ControlPlane.ID) | ||
// require.NoError(t, err) | ||
// }) | ||
|
||
// require.NotNil(t, resp) | ||
|
||
// reqList = sdkkonnectops.ListControlPlanesRequest{ | ||
// Filter: &sdkkonnectcomp.ControlPlaneFilterParameters{ | ||
// ID: &sdkkonnectcomp.ID{ | ||
// StringFieldOEQFilter: &sdkkonnectcomp.StringFieldOEQFilter{ | ||
// Oeq: resp.ControlPlane.GetID(), | ||
// }, | ||
// }, | ||
// }, | ||
// } | ||
// respList, err = sdk.ControlPlanes.ListControlPlanes(ctx, reqList) | ||
// require.NoError(t, err) | ||
// require.NotEmpty(t, respList.ListControlPlanesResponse.Data) | ||
// require.Len(t, respList.ListControlPlanesResponse.Data, 1) | ||
// require.Equal(t, respList.ListControlPlanesResponse.Data[0].ID, resp.ControlPlane.ID) | ||
} |
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,38 @@ | ||
package integration | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const ( | ||
// KonnectPersonalAccessTokenEnv is the environment variable name for the Konnect PAT. | ||
KonnectPersonalAccessTokenEnv = "KONNECT_API_PAT" | ||
// KonnectURLEnv is the environment variable name for the Konnect URL. | ||
KonnectURLEnv = "KONNECT_API_URL" | ||
// KonnectTestRunIDEnv is the environment variable name for the Konnect test run ID. | ||
KonnectTestRunIDEnv = "KONNECT_TEST_RUN_ID" | ||
) | ||
|
||
// KonnectPersonalAccessToken returns the Konnect PAT from the environment. | ||
func KonnectPersonalAccessToken(t *testing.T) string { | ||
token := os.Getenv(KonnectPersonalAccessTokenEnv) | ||
require.NotEmptyf(t, token, "%s is not set", KonnectPersonalAccessTokenEnv) | ||
return token | ||
} | ||
|
||
// KonnectURL returns the Konnect url from the environment. | ||
func KonnectURL(t *testing.T) string { | ||
url := os.Getenv(KonnectURLEnv) | ||
require.NotEmptyf(t, url, "%s is not set", KonnectURLEnv) | ||
return url | ||
} | ||
|
||
// KonnectTestRunID returns the Konnect test run ID from the environment. | ||
func KonnectTestRunID(t *testing.T) string { | ||
id := os.Getenv(KonnectTestRunIDEnv) | ||
require.NotEmptyf(t, id, "%s is not set", KonnectTestRunIDEnv) | ||
return id | ||
} |
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,16 @@ | ||
package integration | ||
|
||
import "testing" | ||
|
||
// NamePrefix returns a prefix for the test name. | ||
func NamePrefix(t *testing.T) string { | ||
return "sdk-konnect-go-test-integration-" + t.Name() | ||
} | ||
|
||
func Labels(t *testing.T) map[string]string { | ||
return map[string]string{ | ||
"sdk-konnect-go": "true", | ||
"test_name": NamePrefix(t), | ||
"test_run_id": KonnectTestRunID(t), | ||
} | ||
} |
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 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdkkonnectops "github.com/Kong/sdk-konnect-go/models/operations" | ||
) | ||
|
||
func TestMe(t *testing.T) { | ||
t.Parallel() | ||
|
||
sdk := SDK(t) | ||
url := KonnectURL(t) | ||
|
||
ctx := context.Background() | ||
// NOTE: This is needed because currently the SDK only lists the prod global API as supported: | ||
// https://github.com/Kong/sdk-konnect-go/blob/999d9a987e1aa7d2e09ac11b1450f4563adf21ea/models/operations/getorganizationsme.go#L10-L12 | ||
respOrg, err := sdk.Me.GetOrganizationsMe(ctx, sdkkonnectops.WithServerURL(url)) | ||
require.NoError(t, err) | ||
require.NotNil(t, respOrg) | ||
require.NotEmpty(t, respOrg.MeOrganization.ID) | ||
require.NotEmpty(t, respOrg.MeOrganization.Name) | ||
require.NotNil(t, respOrg.MeOrganization.State) | ||
require.EqualValues(t, "active", *respOrg.MeOrganization.State) | ||
} |
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,27 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdkkonnectgo "github.com/Kong/sdk-konnect-go" | ||
sdkkonnectcomp "github.com/Kong/sdk-konnect-go/models/components" | ||
) | ||
|
||
// SDK returns a new SDK instance. It requires the KONNECT_API_PAT and KONNECT_API_URL | ||
// environment variables to be set. | ||
func SDK(t *testing.T) *sdkkonnectgo.SDK { | ||
pat := KonnectPersonalAccessToken(t) | ||
url := KonnectURL(t) | ||
sdk := sdkkonnectgo.New( | ||
sdkkonnectgo.WithSecurity( | ||
sdkkonnectcomp.Security{ | ||
PersonalAccessToken: sdkkonnectgo.String(pat), | ||
}, | ||
), | ||
sdkkonnectgo.WithServerURL(url), | ||
) | ||
require.NotNil(t, sdk) | ||
return sdk | ||
} |