Skip to content

testing framework does not work with kpack image inline #1088

@emmjohnson

Description

@emmjohnson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions