Skip to content

Commit f0f0475

Browse files
author
Michal Minář
committed
unit tests: verify manifest link deletions
Signed-off-by: Michal Minář <[email protected]>
1 parent b54b77d commit f0f0475

File tree

1 file changed

+47
-32
lines changed

1 file changed

+47
-32
lines changed

pkg/oc/admin/prune/imageprune/prune_test.go

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,29 @@ func TestImagePruning(t *testing.T) {
4949
registryURL := "https://" + registryHost
5050

5151
tests := []struct {
52-
name string
53-
pruneOverSizeLimit *bool
54-
allImages *bool
55-
pruneRegistry *bool
56-
keepTagRevisions *int
57-
namespace string
58-
images imageapi.ImageList
59-
pods kapi.PodList
60-
streams imageapi.ImageStreamList
61-
rcs kapi.ReplicationControllerList
62-
bcs buildapi.BuildConfigList
63-
builds buildapi.BuildList
64-
dss kapisext.DaemonSetList
65-
deployments kapisext.DeploymentList
66-
dcs appsapi.DeploymentConfigList
67-
rss kapisext.ReplicaSetList
68-
limits map[string][]*kapi.LimitRange
69-
expectedImageDeletions []string
70-
expectedStreamUpdates []string
71-
expectedLayerLinkDeletions []string
72-
expectedBlobDeletions []string
73-
expectedErrorString string
52+
name string
53+
pruneOverSizeLimit *bool
54+
allImages *bool
55+
pruneRegistry *bool
56+
keepTagRevisions *int
57+
namespace string
58+
images imageapi.ImageList
59+
pods kapi.PodList
60+
streams imageapi.ImageStreamList
61+
rcs kapi.ReplicationControllerList
62+
bcs buildapi.BuildConfigList
63+
builds buildapi.BuildList
64+
dss kapisext.DaemonSetList
65+
deployments kapisext.DeploymentList
66+
dcs appsapi.DeploymentConfigList
67+
rss kapisext.ReplicaSetList
68+
limits map[string][]*kapi.LimitRange
69+
expectedImageDeletions []string
70+
expectedStreamUpdates []string
71+
expectedLayerLinkDeletions []string
72+
expectedManifestLinkDeletions []string
73+
expectedBlobDeletions []string
74+
expectedErrorString string
7475
}{
7576
{
7677
name: "1 pod - phase pending - don't prune",
@@ -384,9 +385,10 @@ func TestImagePruning(t *testing.T) {
384385
),
385386
)),
386387
),
387-
expectedImageDeletions: []string{"sha256:0000000000000000000000000000000000000000000000000000000000000004"},
388-
expectedStreamUpdates: []string{"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004"},
389-
expectedBlobDeletions: []string{registryURL + "|" + "sha256:0000000000000000000000000000000000000000000000000000000000000004"},
388+
expectedImageDeletions: []string{"sha256:0000000000000000000000000000000000000000000000000000000000000004"},
389+
expectedStreamUpdates: []string{"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004"},
390+
expectedManifestLinkDeletions: []string{registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004"},
391+
expectedBlobDeletions: []string{registryURL + "|" + "sha256:0000000000000000000000000000000000000000000000000000000000000004"},
390392
},
391393

392394
{
@@ -541,6 +543,12 @@ func TestImagePruning(t *testing.T) {
541543
"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004",
542544
"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000005",
543545
},
546+
expectedManifestLinkDeletions: []string{
547+
registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000001",
548+
registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000003",
549+
registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004",
550+
registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000005",
551+
},
544552
expectedBlobDeletions: []string{
545553
registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000001",
546554
registryURL + "|" + "sha256:0000000000000000000000000000000000000000000000000000000000000003",
@@ -734,6 +742,7 @@ func TestImagePruning(t *testing.T) {
734742
registryURL + "|foo/bar|layer7",
735743
registryURL + "|foo/bar|layer8",
736744
},
745+
expectedManifestLinkDeletions: []string{registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004"},
737746
expectedBlobDeletions: []string{
738747
registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000004",
739748
registryURL + "|layer5",
@@ -771,6 +780,7 @@ func TestImagePruning(t *testing.T) {
771780
registryURL + "|foo/bar|layer7",
772781
registryURL + "|foo/bar|layer8",
773782
},
783+
expectedManifestLinkDeletions: []string{registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004"},
774784
expectedBlobDeletions: []string{
775785
registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000004",
776786
registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000005",
@@ -814,9 +824,10 @@ func TestImagePruning(t *testing.T) {
814824
limits: map[string][]*kapi.LimitRange{
815825
"foo": testutil.LimitList(100, 200),
816826
},
817-
expectedImageDeletions: []string{"sha256:0000000000000000000000000000000000000000000000000000000000000003"},
818-
expectedStreamUpdates: []string{"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000003"},
819-
expectedBlobDeletions: []string{registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000003"},
827+
expectedImageDeletions: []string{"sha256:0000000000000000000000000000000000000000000000000000000000000003"},
828+
expectedStreamUpdates: []string{"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000003"},
829+
expectedManifestLinkDeletions: []string{registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000003"},
830+
expectedBlobDeletions: []string{registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000003"},
820831
},
821832

822833
{
@@ -848,6 +859,10 @@ func TestImagePruning(t *testing.T) {
848859
},
849860
expectedImageDeletions: []string{"sha256:0000000000000000000000000000000000000000000000000000000000000002", "sha256:0000000000000000000000000000000000000000000000000000000000000004"},
850861
expectedStreamUpdates: []string{"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000002", "bar/foo|sha256:0000000000000000000000000000000000000000000000000000000000000004"},
862+
expectedManifestLinkDeletions: []string{
863+
registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000002",
864+
registryURL + "|bar/foo|sha256:0000000000000000000000000000000000000000000000000000000000000004",
865+
},
851866
expectedBlobDeletions: []string{
852867
registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000002",
853868
registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000004",
@@ -1002,10 +1017,10 @@ func TestImagePruning(t *testing.T) {
10021017
t.Errorf("unexpected layer link deletions: %s", diff.ObjectDiff(a, e))
10031018
}
10041019

1005-
/*
1006-
TODO: add this check
1007-
expectedManifestLinkDeletions := sets.NewString(test.expectedManifestLinkDeletions...)
1008-
*/
1020+
expectedManifestLinkDeletions := sets.NewString(test.expectedManifestLinkDeletions...)
1021+
if a, e := manifestDeleter.invocations, expectedManifestLinkDeletions; !reflect.DeepEqual(a, e) {
1022+
t.Errorf("unexpected manifest link deletions: %s", diff.ObjectDiff(a, e))
1023+
}
10091024

10101025
expectedBlobDeletions := sets.NewString(test.expectedBlobDeletions...)
10111026
if a, e := blobDeleter.invocations, expectedBlobDeletions; !reflect.DeepEqual(a, e) {

0 commit comments

Comments
 (0)