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

testing framework does not work with kpack image inline #1088

Open
emmjohnson opened this issue Oct 25, 2022 · 1 comment
Open

testing framework does not work with kpack image inline #1088

emmjohnson opened this issue Oct 25, 2022 · 1 comment

Comments

@emmjohnson
Copy link
Contributor

emmjohnson commented Oct 25, 2022

Description of problem

When setting the Expect inline -

			Expect: cartotesting.TemplateTestExpectation{
				ExpectedObject: &v1alpha2.Image{
					TypeMeta: metav1.TypeMeta{
						Kind:       "Image",
						APIVersion: "kpack.io/v1alpha2",
					},
					ObjectMeta: metav1.ObjectMeta{},
					Spec: v1alpha2.ImageSpec{
						Tag:                "my-server/my-repo/my-workload-my-ns",
						ServiceAccountName: "default",
						Builder: corev1.ObjectReference{
							Kind: "ClusterBuilder",
							Name: "default",
						},
						Source: v1alpha12.SourceConfig{
							Blob: &v1alpha12.Blob{
								URL: "my-url",
							},
						},
						Build: &v1alpha2.ImageBuild{
							Env: []corev1.EnvVar{
								{
									Name:  "BP_OCI_SOURCE",
									Value: "my-rev",
								},
							},
							Services: v1alpha2.Services{},
						},
					},
					Status: v1alpha2.ImageStatus{},
				},
			},

The test will fail with -

    templates.go:87: expected does not equal actual: (-expected +actual):
          map[string]any{
          	"apiVersion": string("kpack.io/v1alpha2"),
          	"kind":       string("Image"),
          	"spec": map[string]any{
          		"build": map[string]any{
          			"env":       []any{map[string]any{"name": string("BP_OCI_SOURCE"), "value": string("my-rev")}},
        - 			"resources": map[string]any{},
        + 			"services":  []any{},
          		},

I would have expected the test to succeed.

Proposed solution

  1. Figure out how to coerce kpack Image (and other CRDs) with empty values
  2. Add an ignore fields option to the test where we can omit resources and services in this example
  3. Use ExpectedFile instead of ExpectedObject (workaround) - it works
  4. Use ExpectedUnstructured instead of ExpectObject (another workaround) - it works

Example

<Code snippets that illustrate the when/then blocks>

Additional Context

@squeedee
Copy link
Member

I think we should be looking at how reconciler runtime does a compare

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants