Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration tests added #75

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions backends/tests/e2e/integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//go:build e2e
// +build e2e

package e2e

import (
"context"
"os"
"testing"

authenticationv1 "k8s.io/api/authentication/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubeclient "knative.dev/pkg/client/injection/kube/client"
"knative.dev/reconciler-test/pkg/environment"
"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/eventshub/assert"
"knative.dev/reconciler-test/pkg/feature"
)

var global environment.GlobalEnvironment

func TestMain(m *testing.M) {
global = environment.NewStandardGlobalEnvironment()

// Run the tests.
os.Exit(m.Run())
}

func TestIntegration(t *testing.T) {
t.Parallel()

ctx, env := global.Environment(environment.Managed(t))
env.Test(ctx, t, TesAuth())
}

func TesAuth() *feature.Feature {
f := feature.NewFeature()

authenticatedClientName := feature.MakeRandomK8sName("authenticated-client")
unauthenticatedClientName := feature.MakeRandomK8sName("unauthenticated-client")

SAName := "sa"
SANamespace := "default"

f.Setup("request with authenticated client", func(ctx context.Context, t feature.T) {
tr := &authenticationv1.TokenRequest{
// TODO: fill up
}
Comment on lines +46 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one, I would create a ServiceAccount (SA) with the expected permissions (ClusterRole and ClusterRoleBinding) in test/config/ and apply it as part of the knative_setup (see my top-level review comment) and then this TokenRequest will use that SA to get an associated token and pass it to eventshub.

tr, err := kubeclient.Get(ctx).
CoreV1().
ServiceAccounts(SANamespace).
CreateToken(ctx, SAName, tr, metav1.CreateOptions{})
if err != nil {
t.Fatal("Failed to create token for SA", err)
}
eventshub.Install(authenticatedClientName,
eventshub.StartSenderURL("TODO_backstage_backend_url"),
eventshub.InputHeader("Authorization", "Bearer "+tr.Status.Token),
eventshub.InputMethod("GET"),
)(ctx, t)
})

f.Setup("request with unauthenticated client", eventshub.Install(
unauthenticatedClientName,
eventshub.StartSenderURL("localhost:8080"),
eventshub.InputMethod("GET")),
)

f.Assert("assert response with authenticated client", assert.OnStore(authenticatedClientName).
Match(assert.MatchKind(eventshub.EventResponse)).
Match(assert.MatchStatusCode(202)).
AtLeast(1))
f.Assert("assert response with unauthenticated client", assert.OnStore(unauthenticatedClientName).
Match(assert.MatchKind(eventshub.EventResponse)).
Match(assert.MatchStatusCode(401)).
AtLeast(1))

return f
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
knative.dev/eventing v0.39.1
knative.dev/hack v0.0.0-20231122182901-eb352426ecc1
knative.dev/pkg v0.0.0-20231204120332-9386ad6703ee
knative.dev/reconciler-test v0.0.0-20231024072442-5fb93a792b99
)

require (
Expand Down Expand Up @@ -103,7 +104,6 @@ require (
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
knative.dev/reconciler-test v0.0.0-20231024072442-5fb93a792b99 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions vendor/k8s.io/apimachinery/pkg/api/errors/OWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/k8s.io/apimachinery/pkg/api/meta/OWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/k8s.io/apimachinery/pkg/api/resource/OWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions vendor/k8s.io/apimachinery/pkg/apis/meta/v1/OWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/k8s.io/apimachinery/pkg/util/mergepatch/OWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/k8s.io/apimachinery/pkg/util/strategicpatch/OWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions vendor/k8s.io/client-go/openapi/OWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/k8s.io/client-go/pkg/apis/clientauthentication/OWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/k8s.io/client-go/rest/OWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/k8s.io/client-go/tools/auth/OWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading