Skip to content

Commit

Permalink
unit tests: verify manifest link deletions
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Minář <[email protected]>
  • Loading branch information
Michal Minář committed Apr 24, 2018
1 parent b54b77d commit f0f0475
Showing 1 changed file with 47 additions and 32 deletions.
79 changes: 47 additions & 32 deletions pkg/oc/admin/prune/imageprune/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,29 @@ func TestImagePruning(t *testing.T) {
registryURL := "https://" + registryHost

tests := []struct {
name string
pruneOverSizeLimit *bool
allImages *bool
pruneRegistry *bool
keepTagRevisions *int
namespace string
images imageapi.ImageList
pods kapi.PodList
streams imageapi.ImageStreamList
rcs kapi.ReplicationControllerList
bcs buildapi.BuildConfigList
builds buildapi.BuildList
dss kapisext.DaemonSetList
deployments kapisext.DeploymentList
dcs appsapi.DeploymentConfigList
rss kapisext.ReplicaSetList
limits map[string][]*kapi.LimitRange
expectedImageDeletions []string
expectedStreamUpdates []string
expectedLayerLinkDeletions []string
expectedBlobDeletions []string
expectedErrorString string
name string
pruneOverSizeLimit *bool
allImages *bool
pruneRegistry *bool
keepTagRevisions *int
namespace string
images imageapi.ImageList
pods kapi.PodList
streams imageapi.ImageStreamList
rcs kapi.ReplicationControllerList
bcs buildapi.BuildConfigList
builds buildapi.BuildList
dss kapisext.DaemonSetList
deployments kapisext.DeploymentList
dcs appsapi.DeploymentConfigList
rss kapisext.ReplicaSetList
limits map[string][]*kapi.LimitRange
expectedImageDeletions []string
expectedStreamUpdates []string
expectedLayerLinkDeletions []string
expectedManifestLinkDeletions []string
expectedBlobDeletions []string
expectedErrorString string
}{
{
name: "1 pod - phase pending - don't prune",
Expand Down Expand Up @@ -384,9 +385,10 @@ func TestImagePruning(t *testing.T) {
),
)),
),
expectedImageDeletions: []string{"sha256:0000000000000000000000000000000000000000000000000000000000000004"},
expectedStreamUpdates: []string{"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004"},
expectedBlobDeletions: []string{registryURL + "|" + "sha256:0000000000000000000000000000000000000000000000000000000000000004"},
expectedImageDeletions: []string{"sha256:0000000000000000000000000000000000000000000000000000000000000004"},
expectedStreamUpdates: []string{"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004"},
expectedManifestLinkDeletions: []string{registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004"},
expectedBlobDeletions: []string{registryURL + "|" + "sha256:0000000000000000000000000000000000000000000000000000000000000004"},
},

{
Expand Down Expand Up @@ -541,6 +543,12 @@ func TestImagePruning(t *testing.T) {
"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004",
"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000005",
},
expectedManifestLinkDeletions: []string{
registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000001",
registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000003",
registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004",
registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000005",
},
expectedBlobDeletions: []string{
registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000001",
registryURL + "|" + "sha256:0000000000000000000000000000000000000000000000000000000000000003",
Expand Down Expand Up @@ -734,6 +742,7 @@ func TestImagePruning(t *testing.T) {
registryURL + "|foo/bar|layer7",
registryURL + "|foo/bar|layer8",
},
expectedManifestLinkDeletions: []string{registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004"},
expectedBlobDeletions: []string{
registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000004",
registryURL + "|layer5",
Expand Down Expand Up @@ -771,6 +780,7 @@ func TestImagePruning(t *testing.T) {
registryURL + "|foo/bar|layer7",
registryURL + "|foo/bar|layer8",
},
expectedManifestLinkDeletions: []string{registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000004"},
expectedBlobDeletions: []string{
registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000004",
registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000005",
Expand Down Expand Up @@ -814,9 +824,10 @@ func TestImagePruning(t *testing.T) {
limits: map[string][]*kapi.LimitRange{
"foo": testutil.LimitList(100, 200),
},
expectedImageDeletions: []string{"sha256:0000000000000000000000000000000000000000000000000000000000000003"},
expectedStreamUpdates: []string{"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000003"},
expectedBlobDeletions: []string{registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000003"},
expectedImageDeletions: []string{"sha256:0000000000000000000000000000000000000000000000000000000000000003"},
expectedStreamUpdates: []string{"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000003"},
expectedManifestLinkDeletions: []string{registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000003"},
expectedBlobDeletions: []string{registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000003"},
},

{
Expand Down Expand Up @@ -848,6 +859,10 @@ func TestImagePruning(t *testing.T) {
},
expectedImageDeletions: []string{"sha256:0000000000000000000000000000000000000000000000000000000000000002", "sha256:0000000000000000000000000000000000000000000000000000000000000004"},
expectedStreamUpdates: []string{"foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000002", "bar/foo|sha256:0000000000000000000000000000000000000000000000000000000000000004"},
expectedManifestLinkDeletions: []string{
registryURL + "|foo/bar|sha256:0000000000000000000000000000000000000000000000000000000000000002",
registryURL + "|bar/foo|sha256:0000000000000000000000000000000000000000000000000000000000000004",
},
expectedBlobDeletions: []string{
registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000002",
registryURL + "|sha256:0000000000000000000000000000000000000000000000000000000000000004",
Expand Down Expand Up @@ -1002,10 +1017,10 @@ func TestImagePruning(t *testing.T) {
t.Errorf("unexpected layer link deletions: %s", diff.ObjectDiff(a, e))
}

/*
TODO: add this check
expectedManifestLinkDeletions := sets.NewString(test.expectedManifestLinkDeletions...)
*/
expectedManifestLinkDeletions := sets.NewString(test.expectedManifestLinkDeletions...)
if a, e := manifestDeleter.invocations, expectedManifestLinkDeletions; !reflect.DeepEqual(a, e) {
t.Errorf("unexpected manifest link deletions: %s", diff.ObjectDiff(a, e))
}

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

0 comments on commit f0f0475

Please sign in to comment.