Skip to content

Commit 9a142bc

Browse files
author
Per G. da Silva
committed
Add inline bundle config admission unit tests
Signed-off-by: Per G. da Silva <[email protected]>
1 parent f125d8b commit 9a142bc

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

internal/operator-controller/controllers/clusterextension_admission_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"github.com/stretchr/testify/require"
9+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011

1112
ocv1 "github.com/operator-framework/operator-controller/api/v1"
@@ -448,6 +449,54 @@ func TestClusterExtensionAdmissionInstall(t *testing.T) {
448449
}
449450
}
450451

452+
func Test_ClusterExtensionAdmissionInlineConfig(t *testing.T) {
453+
t.Parallel()
454+
for _, tc := range []struct {
455+
name string
456+
configBytes []byte
457+
errMsg string
458+
}{
459+
{
460+
name: "rejects valid json that is not of an object type",
461+
configBytes: []byte(`true`),
462+
errMsg: "spec.config.inline in body must be of type object",
463+
},
464+
{
465+
name: "accepts valid json object",
466+
configBytes: []byte(`{"key": "value"}`),
467+
},
468+
} {
469+
t.Run(tc.name, func(t *testing.T) {
470+
t.Parallel()
471+
cl := newClient(t)
472+
err := cl.Create(context.Background(), buildClusterExtension(ocv1.ClusterExtensionSpec{
473+
Source: ocv1.SourceConfig{
474+
SourceType: "Catalog",
475+
Catalog: &ocv1.CatalogFilter{
476+
PackageName: "package",
477+
},
478+
},
479+
Namespace: "default",
480+
ServiceAccount: ocv1.ServiceAccountReference{
481+
Name: "default",
482+
},
483+
Config: &ocv1.ClusterExtensionConfig{
484+
ConfigType: ocv1.ClusterExtensionConfigTypeInline,
485+
Inline: &apiextensionsv1.JSON{
486+
Raw: tc.configBytes,
487+
},
488+
},
489+
}))
490+
if tc.errMsg == "" {
491+
require.NoError(t, err, "unexpected error for inline bundle configuration %q: %w", string(tc.configBytes), err)
492+
} else {
493+
require.Error(t, err)
494+
require.Contains(t, err.Error(), tc.errMsg)
495+
}
496+
})
497+
}
498+
}
499+
451500
func buildClusterExtension(spec ocv1.ClusterExtensionSpec) *ocv1.ClusterExtension {
452501
return &ocv1.ClusterExtension{
453502
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)