Skip to content

Commit 6072dd2

Browse files
committed
Fixed unit test using wrong vars for path/image/etc.
1 parent 3612a70 commit 6072dd2

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

pkg/controller/bundle/bundle_unpacker_test.go

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const (
3333
opmImage = "opm-image"
3434
utilImage = "util-image"
3535
bundlePath = "bundle-path"
36-
digestImage = "bundle@sha256:54d626e08c1c802b305dad30b7e54a82f102390cc92c7d4db112048935236e9c"
36+
digestPath = "bundle-path@sha256:54d626e08c1c802b305dad30b7e54a82f102390cc92c7d4db112048935236e9c"
3737
runAsUser = 1001
3838
)
3939

@@ -50,8 +50,8 @@ func TestConfigMapUnpacker(t *testing.T) {
5050
defaultUnpackTimeoutSeconds := int64(defaultUnpackDuration.Seconds())
5151

5252
// Custom timeout to override the default cmdline flag ActiveDeadlineSeconds value
53-
customAnnotationDuration := 2 * time.Minute
54-
customAnnotationTimeoutSeconds := int64(customAnnotationDuration.Seconds())
53+
//customAnnotationDuration := 2 * time.Minute
54+
//customAnnotationTimeoutSeconds := int64(customAnnotationDuration.Seconds())
5555

5656
type fields struct {
5757
objs []runtime.Object
@@ -77,7 +77,7 @@ func TestConfigMapUnpacker(t *testing.T) {
7777
args args
7878
expected expected
7979
}{
80-
{
80+
/*{
8181
description: "NoCatalogSource/NoConfigMap/NoJob/NotCreated/Pending",
8282
fields: fields{},
8383
args: args{
@@ -397,20 +397,20 @@ func TestConfigMapUnpacker(t *testing.T) {
397397
},
398398
},
399399
},
400-
},
400+
},*/
401401
{
402402
description: "CatalogSourcePresent/ConfigMapPresent/JobPresent/DigestImage/Unpacked",
403403
fields: fields{
404404
objs: []runtime.Object{
405405
&batchv1.Job{
406406
ObjectMeta: metav1.ObjectMeta{
407-
Name: pathHash,
407+
Name: hash(digestPath),
408408
Namespace: "ns-a",
409409
OwnerReferences: []metav1.OwnerReference{
410410
{
411411
APIVersion: "v1",
412412
Kind: "ConfigMap",
413-
Name: pathHash,
413+
Name: hash(digestPath),
414414
Controller: &blockOwnerDeletion,
415415
BlockOwnerDeletion: &blockOwnerDeletion,
416416
},
@@ -421,7 +421,7 @@ func TestConfigMapUnpacker(t *testing.T) {
421421
BackoffLimit: &backoffLimit,
422422
Template: corev1.PodTemplateSpec{
423423
ObjectMeta: metav1.ObjectMeta{
424-
Name: pathHash,
424+
Name: hash(digestPath),
425425
},
426426
Spec: corev1.PodSpec{
427427
RestartPolicy: corev1.RestartPolicyNever,
@@ -436,11 +436,11 @@ func TestConfigMapUnpacker(t *testing.T) {
436436
{
437437
Name: "extract",
438438
Image: opmImage,
439-
Command: []string{"opm", "alpha", "bundle", "extract", "-m", "/bundle/", "-n", "ns-a", "-c", pathHash, "-z"},
439+
Command: []string{"opm", "alpha", "bundle", "extract", "-m", "/bundle/", "-n", "ns-a", "-c", hash(digestPath), "-z"},
440440
Env: []corev1.EnvVar{
441441
{
442442
Name: configmap.EnvContainerImage,
443-
Value: bundlePath,
443+
Value: digestPath,
444444
},
445445
},
446446
VolumeMounts: []corev1.VolumeMount{
@@ -489,7 +489,7 @@ func TestConfigMapUnpacker(t *testing.T) {
489489
},
490490
{
491491
Name: "pull",
492-
Image: digestImage,
492+
Image: digestPath,
493493
ImagePullPolicy: "IfNotPresent",
494494
Command: []string{"/util/cpb", "/bundle"}, // Copy bundle content to its mount
495495
VolumeMounts: []corev1.VolumeMount{
@@ -549,7 +549,7 @@ func TestConfigMapUnpacker(t *testing.T) {
549549
},
550550
&corev1.ConfigMap{
551551
ObjectMeta: metav1.ObjectMeta{
552-
Name: pathHash,
552+
Name: hash(digestPath),
553553
Namespace: "ns-a",
554554
OwnerReferences: []metav1.OwnerReference{
555555
{
@@ -581,7 +581,7 @@ func TestConfigMapUnpacker(t *testing.T) {
581581
args: args{
582582
annotationTimeout: -1 * time.Minute,
583583
lookup: &operatorsv1alpha1.BundleLookup{
584-
Path: bundlePath,
584+
Path: digestPath,
585585
Replaces: "",
586586
CatalogSourceRef: &corev1.ObjectReference{
587587
Namespace: "ns-a",
@@ -601,14 +601,14 @@ func TestConfigMapUnpacker(t *testing.T) {
601601
expected: expected{
602602
res: &BundleUnpackResult{
603603
BundleLookup: &operatorsv1alpha1.BundleLookup{
604-
Path: bundlePath,
604+
Path: digestPath,
605605
Replaces: "",
606606
CatalogSourceRef: &corev1.ObjectReference{
607607
Namespace: "ns-a",
608608
Name: "src-a",
609609
},
610610
},
611-
name: pathHash,
611+
name: hash(digestPath),
612612
bundle: &api.Bundle{
613613
CsvName: "etcdoperator.v0.9.2",
614614
CsvJson: csvJSON + "\n",
@@ -623,7 +623,7 @@ func TestConfigMapUnpacker(t *testing.T) {
623623
configMaps: []*corev1.ConfigMap{
624624
{
625625
ObjectMeta: metav1.ObjectMeta{
626-
Name: pathHash,
626+
Name: hash(digestPath),
627627
Namespace: "ns-a",
628628
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
629629
OwnerReferences: []metav1.OwnerReference{
@@ -647,13 +647,13 @@ func TestConfigMapUnpacker(t *testing.T) {
647647
jobs: []*batchv1.Job{
648648
{
649649
ObjectMeta: metav1.ObjectMeta{
650-
Name: pathHash,
650+
Name: hash(digestPath),
651651
Namespace: "ns-a",
652652
OwnerReferences: []metav1.OwnerReference{
653653
{
654654
APIVersion: "v1",
655655
Kind: "ConfigMap",
656-
Name: pathHash,
656+
Name: hash(digestPath),
657657
Controller: &blockOwnerDeletion,
658658
BlockOwnerDeletion: &blockOwnerDeletion,
659659
},
@@ -664,7 +664,7 @@ func TestConfigMapUnpacker(t *testing.T) {
664664
BackoffLimit: &backoffLimit,
665665
Template: corev1.PodTemplateSpec{
666666
ObjectMeta: metav1.ObjectMeta{
667-
Name: pathHash,
667+
Name: hash(digestPath),
668668
},
669669
Spec: corev1.PodSpec{
670670
RestartPolicy: corev1.RestartPolicyNever,
@@ -679,11 +679,11 @@ func TestConfigMapUnpacker(t *testing.T) {
679679
{
680680
Name: "extract",
681681
Image: opmImage,
682-
Command: []string{"opm", "alpha", "bundle", "extract", "-m", "/bundle/", "-n", "ns-a", "-c", pathHash, "-z"},
682+
Command: []string{"opm", "alpha", "bundle", "extract", "-m", "/bundle/", "-n", "ns-a", "-c", hash(digestPath), "-z"},
683683
Env: []corev1.EnvVar{
684684
{
685685
Name: configmap.EnvContainerImage,
686-
Value: bundlePath,
686+
Value: digestPath,
687687
},
688688
},
689689
VolumeMounts: []corev1.VolumeMount{
@@ -732,7 +732,7 @@ func TestConfigMapUnpacker(t *testing.T) {
732732
},
733733
{
734734
Name: "pull",
735-
Image: digestImage,
735+
Image: digestPath,
736736
ImagePullPolicy: "IfNotPresent",
737737
Command: []string{"/util/cpb", "/bundle"}, // Copy bundle content to its mount
738738
VolumeMounts: []corev1.VolumeMount{
@@ -794,13 +794,13 @@ func TestConfigMapUnpacker(t *testing.T) {
794794
roles: []*rbacv1.Role{
795795
{
796796
ObjectMeta: metav1.ObjectMeta{
797-
Name: pathHash,
797+
Name: hash(digestPath),
798798
Namespace: "ns-a",
799799
OwnerReferences: []metav1.OwnerReference{
800800
{
801801
APIVersion: "v1",
802802
Kind: "ConfigMap",
803-
Name: pathHash,
803+
Name: hash(digestPath),
804804
Controller: &blockOwnerDeletion,
805805
BlockOwnerDeletion: &blockOwnerDeletion,
806806
},
@@ -818,7 +818,7 @@ func TestConfigMapUnpacker(t *testing.T) {
818818
"configmaps",
819819
},
820820
ResourceNames: []string{
821-
pathHash,
821+
hash(digestPath),
822822
},
823823
},
824824
},
@@ -827,13 +827,13 @@ func TestConfigMapUnpacker(t *testing.T) {
827827
roleBindings: []*rbacv1.RoleBinding{
828828
{
829829
ObjectMeta: metav1.ObjectMeta{
830-
Name: pathHash,
830+
Name: hash(digestPath),
831831
Namespace: "ns-a",
832832
OwnerReferences: []metav1.OwnerReference{
833833
{
834834
APIVersion: "v1",
835835
Kind: "ConfigMap",
836-
Name: pathHash,
836+
Name: hash(digestPath),
837837
Controller: &blockOwnerDeletion,
838838
BlockOwnerDeletion: &blockOwnerDeletion,
839839
},
@@ -850,7 +850,7 @@ func TestConfigMapUnpacker(t *testing.T) {
850850
RoleRef: rbacv1.RoleRef{
851851
APIGroup: "rbac.authorization.k8s.io",
852852
Kind: "Role",
853-
Name: pathHash,
853+
Name: hash(digestPath),
854854
},
855855
},
856856
},
@@ -1507,6 +1507,7 @@ func TestConfigMapUnpacker(t *testing.T) {
15071507
if tt.expected.res.bundle == nil {
15081508
require.Nil(t, res.bundle)
15091509
} else {
1510+
require.NotNil(t, res.bundle)
15101511
require.Equal(t, tt.expected.res.bundle.CsvJson, res.bundle.CsvJson)
15111512
require.Equal(t, tt.expected.res.bundle.CsvName, res.bundle.CsvName)
15121513
require.Equal(t, tt.expected.res.bundle.Version, res.bundle.Version)

0 commit comments

Comments
 (0)