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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃尡 test/e2e/virtual/apiexport: make authorizer test self-contained #2611

Merged
merged 1 commit into from
Jan 17, 2023

Conversation

s-urbaniak
Copy link
Contributor

Summary

This makes the e2e test for virtual apiexport authorizer self-contained. The apply method will be used to add new e2e tests asserting existing issues.

Related issue(s)

export, err := user1KcpClient.Cluster(serviceProvider1Path).ApisV1alpha1().APIExports().Get(ctx, "wild.wild.west", metav1.GetOptions{})
require.NoError(t, err, "error getting APIExport %s|%s", serviceProvider1Path, export.Name)
t.Logf("install sherriffs API resource schema, API export, permissions for user-3 to be able to bind to the export in service provider workspace %q", serviceProvider1Path)
require.NoError(t, apply(t, ctx, serviceProvider1Path, framework.UserConfig("user-1", rest.CopyConfig(cfg)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we doing this as user-1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

user-1 is admin of serviceprovider workspace

Copy link
Contributor

Choose a reason for hiding this comment

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

Yikes, hope we can figure out how to dynamically inject more users in the future at runtime so that we can make these semantically useful. Can you track this as a follow-up for e2e in general?

require.NoError(t, err, "error getting APIExport %s|%s", serviceProvider1Path, export.Name)
t.Logf("install sherriffs API resource schema, API export, permissions for user-3 to be able to bind to the export in service provider workspace %q", serviceProvider1Path)
require.NoError(t, apply(t, ctx, serviceProvider1Path, framework.UserConfig("user-1", rest.CopyConfig(cfg)),
&apisv1alpha1.APIResourceSchema{
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we auto-gen an APIRS from the Go types? Are we using something special here for a reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there are no go types for these test types (sherriffs/cowboys) available. these types are just for testing, we don't maintain them.

Copy link
Contributor

Choose a reason for hiding this comment

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

test/e2e/fixtures/wildwest/apis/wildwest/v1alpha1/types.go:type Cowboy struct {

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

he, i had no idea, however do we want to depend on central fixtures? i was having the impression we want to get rid of it.

Copy link
Member

Choose a reason for hiding this comment

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

using those types and clients is fine IMO. "getting rid of the fixtures" is about helper functions built around those types. We don't want them.

Copy link
Member

Choose a reason for hiding this comment

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

And rule of thumb: don't build anything special into shared fixtures. If you need them to change, chance is high that you better make a copy.

test/e2e/virtual/apiexport/authorizer_test.go Outdated Show resolved Hide resolved
test/e2e/virtual/apiexport/authorizer_test.go Outdated Show resolved Hide resolved
Spec: apisv1alpha1.APIBindingSpec{
Reference: apisv1alpha1.BindingReference{
Export: &apisv1alpha1.ExportBindingReference{
Path: serviceProvider1Path.String(),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: if serviceProvider1 is for sherrifs and serviceProvider2 is cowboys, can we update to sherrifsProvider and cowboysProvider?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh sure

test/e2e/virtual/apiexport/authorizer_test.go Show resolved Hide resolved
return groupExists(groups, wildwest.GroupName) && groupExists(groups, "wild.wild.west"), nil
})
require.NoError(t, err)
return groupExists(groups, wildwest.GroupName) && groupExists(groups, "wild.wild.west"), ""
Copy link
Contributor

Choose a reason for hiding this comment

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

return the missing but expected groups, so this errors nicely

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let's do this as a follow-up, i didn't change the groupExists method here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good - track the follow-ups however you want.

test/e2e/virtual/apiexport/authorizer_test.go Outdated Show resolved Hide resolved
test/e2e/virtual/apiexport/authorizer_test.go Show resolved Hide resolved
dynamicResource = dynamicClient.Cluster(workspace).Resource(mapping.Resource)
}

bytes, err := json.Marshal(obj)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use the scheme

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wdym, do you have a reference?

Copy link
Contributor

Choose a reason for hiding this comment

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

You want a structured encoder from a scheme that has the type registered - I don't have a good link but would just auto-complete my way there.

@stevekuznetsov
Copy link
Contributor

All remaining comments are minor and can be tackled in follow-ups.

/lgtm
/approve

@s-urbaniak s-urbaniak added approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. labels Jan 16, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 16, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: stevekuznetsov

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@s-urbaniak
Copy link
Contributor Author

/refresh

@openshift-merge-robot openshift-merge-robot merged commit 80bc834 into kcp-dev:main Jan 17, 2023
@s-urbaniak s-urbaniak deleted the self-contained-e2e branch January 17, 2023 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants