Skip to content

Commit 2a5c923

Browse files
committed
Generate hash just once for digestPath
Signed-off-by: Daniel Franz <[email protected]>
1 parent 9816763 commit 2a5c923

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

pkg/controller/bundle/bundle_unpacker_test.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939

4040
func TestConfigMapUnpacker(t *testing.T) {
4141
pathHash := hash(bundlePath)
42+
digestHash := hash(digestPath)
4243
start := metav1.Now()
4344
now := func() metav1.Time {
4445
return start
@@ -404,13 +405,13 @@ func TestConfigMapUnpacker(t *testing.T) {
404405
objs: []runtime.Object{
405406
&batchv1.Job{
406407
ObjectMeta: metav1.ObjectMeta{
407-
Name: hash(digestPath),
408+
Name: digestHash,
408409
Namespace: "ns-a",
409410
OwnerReferences: []metav1.OwnerReference{
410411
{
411412
APIVersion: "v1",
412413
Kind: "ConfigMap",
413-
Name: hash(digestPath),
414+
Name: digestHash,
414415
Controller: &blockOwnerDeletion,
415416
BlockOwnerDeletion: &blockOwnerDeletion,
416417
},
@@ -421,7 +422,7 @@ func TestConfigMapUnpacker(t *testing.T) {
421422
BackoffLimit: &backoffLimit,
422423
Template: corev1.PodTemplateSpec{
423424
ObjectMeta: metav1.ObjectMeta{
424-
Name: hash(digestPath),
425+
Name: digestHash,
425426
},
426427
Spec: corev1.PodSpec{
427428
RestartPolicy: corev1.RestartPolicyNever,
@@ -436,7 +437,7 @@ func TestConfigMapUnpacker(t *testing.T) {
436437
{
437438
Name: "extract",
438439
Image: opmImage,
439-
Command: []string{"opm", "alpha", "bundle", "extract", "-m", "/bundle/", "-n", "ns-a", "-c", hash(digestPath), "-z"},
440+
Command: []string{"opm", "alpha", "bundle", "extract", "-m", "/bundle/", "-n", "ns-a", "-c", digestHash, "-z"},
440441
Env: []corev1.EnvVar{
441442
{
442443
Name: configmap.EnvContainerImage,
@@ -549,7 +550,7 @@ func TestConfigMapUnpacker(t *testing.T) {
549550
},
550551
&corev1.ConfigMap{
551552
ObjectMeta: metav1.ObjectMeta{
552-
Name: hash(digestPath),
553+
Name: digestHash,
553554
Namespace: "ns-a",
554555
OwnerReferences: []metav1.OwnerReference{
555556
{
@@ -608,7 +609,7 @@ func TestConfigMapUnpacker(t *testing.T) {
608609
Name: "src-a",
609610
},
610611
},
611-
name: hash(digestPath),
612+
name: digestHash,
612613
bundle: &api.Bundle{
613614
CsvName: "etcdoperator.v0.9.2",
614615
CsvJson: csvJSON + "\n",
@@ -623,7 +624,7 @@ func TestConfigMapUnpacker(t *testing.T) {
623624
configMaps: []*corev1.ConfigMap{
624625
{
625626
ObjectMeta: metav1.ObjectMeta{
626-
Name: hash(digestPath),
627+
Name: digestHash,
627628
Namespace: "ns-a",
628629
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
629630
OwnerReferences: []metav1.OwnerReference{
@@ -647,13 +648,13 @@ func TestConfigMapUnpacker(t *testing.T) {
647648
jobs: []*batchv1.Job{
648649
{
649650
ObjectMeta: metav1.ObjectMeta{
650-
Name: hash(digestPath),
651+
Name: digestHash,
651652
Namespace: "ns-a",
652653
OwnerReferences: []metav1.OwnerReference{
653654
{
654655
APIVersion: "v1",
655656
Kind: "ConfigMap",
656-
Name: hash(digestPath),
657+
Name: digestHash,
657658
Controller: &blockOwnerDeletion,
658659
BlockOwnerDeletion: &blockOwnerDeletion,
659660
},
@@ -664,7 +665,7 @@ func TestConfigMapUnpacker(t *testing.T) {
664665
BackoffLimit: &backoffLimit,
665666
Template: corev1.PodTemplateSpec{
666667
ObjectMeta: metav1.ObjectMeta{
667-
Name: hash(digestPath),
668+
Name: digestHash,
668669
},
669670
Spec: corev1.PodSpec{
670671
RestartPolicy: corev1.RestartPolicyNever,
@@ -679,7 +680,7 @@ func TestConfigMapUnpacker(t *testing.T) {
679680
{
680681
Name: "extract",
681682
Image: opmImage,
682-
Command: []string{"opm", "alpha", "bundle", "extract", "-m", "/bundle/", "-n", "ns-a", "-c", hash(digestPath), "-z"},
683+
Command: []string{"opm", "alpha", "bundle", "extract", "-m", "/bundle/", "-n", "ns-a", "-c", digestHash, "-z"},
683684
Env: []corev1.EnvVar{
684685
{
685686
Name: configmap.EnvContainerImage,
@@ -794,13 +795,13 @@ func TestConfigMapUnpacker(t *testing.T) {
794795
roles: []*rbacv1.Role{
795796
{
796797
ObjectMeta: metav1.ObjectMeta{
797-
Name: hash(digestPath),
798+
Name: digestHash,
798799
Namespace: "ns-a",
799800
OwnerReferences: []metav1.OwnerReference{
800801
{
801802
APIVersion: "v1",
802803
Kind: "ConfigMap",
803-
Name: hash(digestPath),
804+
Name: digestHash,
804805
Controller: &blockOwnerDeletion,
805806
BlockOwnerDeletion: &blockOwnerDeletion,
806807
},
@@ -818,7 +819,7 @@ func TestConfigMapUnpacker(t *testing.T) {
818819
"configmaps",
819820
},
820821
ResourceNames: []string{
821-
hash(digestPath),
822+
digestHash,
822823
},
823824
},
824825
},
@@ -827,13 +828,13 @@ func TestConfigMapUnpacker(t *testing.T) {
827828
roleBindings: []*rbacv1.RoleBinding{
828829
{
829830
ObjectMeta: metav1.ObjectMeta{
830-
Name: hash(digestPath),
831+
Name: digestHash,
831832
Namespace: "ns-a",
832833
OwnerReferences: []metav1.OwnerReference{
833834
{
834835
APIVersion: "v1",
835836
Kind: "ConfigMap",
836-
Name: hash(digestPath),
837+
Name: digestHash,
837838
Controller: &blockOwnerDeletion,
838839
BlockOwnerDeletion: &blockOwnerDeletion,
839840
},
@@ -850,7 +851,7 @@ func TestConfigMapUnpacker(t *testing.T) {
850851
RoleRef: rbacv1.RoleRef{
851852
APIGroup: "rbac.authorization.k8s.io",
852853
Kind: "Role",
853-
Name: hash(digestPath),
854+
Name: digestHash,
854855
},
855856
},
856857
},

0 commit comments

Comments
 (0)