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

🌱 add missing unit tests for the pathannotation admission plugin #2535

Merged
merged 2 commits into from
Jan 5, 2023

Conversation

p0lyn0mial
Copy link
Contributor

Related issue(s)

#2510

@openshift-ci openshift-ci bot requested review from ncdc and sttts January 2, 2023 18:03
@p0lyn0mial p0lyn0mial removed the request for review from ncdc January 2, 2023 18:03
@openshift-ci openshift-ci bot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Jan 2, 2023
@s-urbaniak
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 3, 2023
expectError: true,
},
{
name: "admission is not applied to logicalclusters", // would panic since no admission obj
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the comment mean? It would panic, but it doesn't, and why. ..?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was lazy - instead of providing an object and making sure it doesn't have the annotation set i assumed it would panic if the admission would apply. Anyway I added an object and provided objectWithoutPathAnnotation function.

ObjectMeta: metav1.ObjectMeta{
Name: corev1alpha1.LogicalClusterName,
Annotations: map[string]string{
core.LogicalClusterPathAnnotationKey: "root:foo",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this root when the clusterName passed in is test-cluster?

Copy link
Contributor Author

@p0lyn0mial p0lyn0mial Jan 4, 2023

Choose a reason for hiding this comment

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

changed the clusterName to foo

admissionVerb: admission.Create,
admissionResource: apisv1alpha1.SchemeGroupVersion.WithResource("apiexports"),
admissionObject: &apisv1alpha1.APIExport{},
admissionContext: wellKnownAdmissionContext,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: factoring out the data that drives the test would make this easier to read (and explicit, not implicit):

		{
			name:                    "happy path: an APIExport is annotated with a path",
			admissionVerb:           admission.Create,
			admissionResource:       apisv1alpha1.SchemeGroupVersion.WithResource("apiexports"),
			admissionObject:         &apisv1alpha1.APIExport{},
			admissionContext:        admissionContextFor("root:foo"),
			getLogicalCluster:       getCluster("root:foo"),
			validateAdmissionObject: objectHasPathAnnotation("root:foo"),
		},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -101,20 +105,20 @@ func (p *pathAnnotationPlugin) Admit(ctx context.Context, a admission.Attributes
return nil
}

this, err := p.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName)
cluster, err := p.getLogicalCluster(clusterName, corev1alpha1.LogicalClusterName)
Copy link
Contributor

Choose a reason for hiding this comment

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

super-nit: can you make these logicalCluster please? xref #2524

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it looks like you already did it in another PR :)

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 4, 2023
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 4, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 4, 2023
@p0lyn0mial
Copy link
Contributor Author

@s-urbaniak @stevekuznetsov i've updated the PR, PTAL.


// getLogicalCluster is a convenience function for easier unit testing,
// it reads a LogicalCluster resource with the given name and from the given cluster.
getLogicalCluster func(clusterName logicalcluster.Name, name string) (*corev1alpha1.LogicalCluster, error)
Copy link
Member

Choose a reason for hiding this comment

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

no need for name

@sttts
Copy link
Member

sttts commented Jan 5, 2023

/retest
/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 5, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 5, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sttts

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 5, 2023
@sttts
Copy link
Member

sttts commented Jan 5, 2023

/retest

@openshift-merge-robot openshift-merge-robot merged commit c693005 into kcp-dev:main Jan 5, 2023
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. area/workspaces kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants