Skip to content

Commit 36ae501

Browse files
test
1 parent 36809b3 commit 36ae501

File tree

56 files changed

+90
-67045
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+90
-67045
lines changed

Makefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,9 @@ generate: $(CONTROLLER_GEN) #EXHELP Generate code containing DeepCopy, DeepCopyI
167167
$(CONTROLLER_GEN) --load-build-tags=$(GO_BUILD_TAGS) object:headerFile="hack/boilerplate.go.txt" paths="./..."
168168

169169
.PHONY: verify
170-
verify: k8s-pin kind-verify-versions fmt generate manifests crd-ref-docs generate-test-data #HELP Verify all generated code is up-to-date. Runs k8s-pin instead of just tidy.
170+
verify: k8s-pin kind-verify-versions fmt generate manifests crd-ref-docs #HELP Verify all generated code is up-to-date. Runs k8s-pin instead of just tidy.
171171
git diff --exit-code
172172

173-
# Renders registry+v1 bundles in test/convert
174-
# Used by CI in verify to catch regressions in the registry+v1 -> plain conversion code
175-
.PHONY: generate-test-data
176-
generate-test-data:
177-
go run test/convert/generate-manifests.go
178-
179173
.PHONY: fix-lint
180174
fix-lint: $(GOLANGCI_LINT) #EXHELP Fix lint issues
181175
$(GOLANGCI_LINT) run --fix --build-tags $(GO_BUILD_TAGS) $(GOLANGCI_LINT_ARGS)

internal/operator-controller/rukpak/render/render_test.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
package render_test
22

33
import (
4+
"cmp"
45
"errors"
56
"fmt"
7+
"os"
8+
"path/filepath"
69
"reflect"
10+
"slices"
11+
"strings"
712
"testing"
813

914
"github.com/stretchr/testify/require"
1015
appsv1 "k8s.io/api/apps/v1"
1116
corev1 "k8s.io/api/core/v1"
1217
"sigs.k8s.io/controller-runtime/pkg/client"
18+
"sigs.k8s.io/yaml"
1319

1420
"github.com/operator-framework/api/pkg/operators/v1alpha1"
1521

1622
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle"
23+
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
1724
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render"
25+
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/registryv1"
1826
. "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing"
1927
)
2028

@@ -267,3 +275,84 @@ func Test_BundleValidatorCallsAllValidationFnsInOrder(t *testing.T) {
267275
require.NoError(t, val.Validate(nil))
268276
require.Equal(t, "hi", actual)
269277
}
278+
279+
// This test ensures consistent rendering behavior for registry+v1 bundles:
280+
// - Uses the bundles defined in the testdata directory
281+
// - Renders manifests using the registryv1 renderer
282+
// - Sorts rendered objects by Kind, Namespace, and Name to ensure deterministic output
283+
// - Writes the results to a temporary directory for inspection
284+
// - Ensures the rendering completes without error
285+
// - Automatically cleans up the generated files after the test completes
286+
//
287+
// This was introduced to prevent flaky diffs caused by non-deterministic manifest ordering.
288+
// Related issue: https://github.com/operator-framework/operator-controller/pull/1895
289+
func Test_RenderRegistryV1Bundle_GenerateAndAutoCleanup(t *testing.T) {
290+
bundleRoot := "testdata/bundles"
291+
292+
testCases := []struct {
293+
name string
294+
installNamespace string
295+
watchNamespace string
296+
bundle string
297+
testCaseName string
298+
}{
299+
{
300+
name: "AllNamespaces",
301+
installNamespace: "argocd-system",
302+
watchNamespace: "",
303+
bundle: "argocd-operator.v0.6.0",
304+
testCaseName: "all-namespaces",
305+
},
306+
{
307+
name: "SingleNamespaces",
308+
installNamespace: "argocd-system",
309+
watchNamespace: "argocd-watch",
310+
bundle: "argocd-operator.v0.6.0",
311+
testCaseName: "single-namespace",
312+
},
313+
{
314+
name: "OwnNamespaces",
315+
installNamespace: "argocd-system",
316+
watchNamespace: "argocd-system",
317+
bundle: "argocd-operator.v0.6.0",
318+
testCaseName: "own-namespace",
319+
},
320+
}
321+
322+
for _, tc := range testCases {
323+
t.Run(tc.name, func(t *testing.T) {
324+
bundlePath := filepath.Join(bundleRoot, tc.bundle)
325+
outputDir := filepath.Join(t.TempDir(), tc.bundle, tc.testCaseName)
326+
327+
fs := os.DirFS(bundlePath)
328+
bundle, err := source.FromFS(fs).GetBundle()
329+
require.NoError(t, err)
330+
331+
rendered, err := registryv1.Renderer.Render(bundle, tc.installNamespace,
332+
render.WithTargetNamespaces(tc.watchNamespace))
333+
require.NoError(t, err)
334+
335+
sorted := slices.SortedFunc(slices.Values(rendered), orderByKindNamespaceName)
336+
337+
require.NoError(t, os.MkdirAll(outputDir, os.ModePerm))
338+
339+
for idx, obj := range sorted {
340+
kind := obj.GetObjectKind().GroupVersionKind().Kind
341+
filename := fmt.Sprintf("%02d_%s_%s.yaml", idx, strings.ToLower(kind), obj.GetName())
342+
filePath := filepath.Join(outputDir, filename)
343+
344+
data, err := yaml.Marshal(obj)
345+
require.NoError(t, err)
346+
require.NoError(t, os.WriteFile(filePath, data, 0600))
347+
}
348+
})
349+
}
350+
}
351+
352+
func orderByKindNamespaceName(a client.Object, b client.Object) int {
353+
return cmp.Or(
354+
cmp.Compare(a.GetObjectKind().GroupVersionKind().Kind, b.GetObjectKind().GroupVersionKind().Kind),
355+
cmp.Compare(a.GetNamespace(), b.GetNamespace()),
356+
cmp.Compare(a.GetName(), b.GetName()),
357+
)
358+
}

0 commit comments

Comments
 (0)