-
Notifications
You must be signed in to change notification settings - Fork 18
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} | ||
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 | ||
} |
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.
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.
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.
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.
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.
There was a problem hiding this comment.
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 theknative_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.