-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy: split selection of images to be copied
Following PR splits `copyMultipleImages` into a new function called `prepareEditInstances` which returns a list of `ListEdit`. `prepareEditInstances` does that in these two steps * How to copy via ListOperation * What to copy by the content of the returned list. See newly added unit test to see how it is used. Signed-off-by: Aditya R <[email protected]>
- Loading branch information
Showing
2 changed files
with
77 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package copy | ||
|
||
import ( | ||
"testing" | ||
|
||
digest "github.com/opencontainers/go-digest" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPrepareEditList(t *testing.T) { | ||
// Test CopyAllImages | ||
options := Options{} | ||
instances := []digest.Digest{ | ||
digest.Digest("sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270"), | ||
digest.Digest("sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), | ||
digest.Digest("sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"), | ||
} | ||
|
||
instancesToEdit, imagesToCopy := prepareEditList(instances, &options) | ||
assert.Equal(t, imagesToCopy, len(instances)) | ||
assert.Equal(t, instancesToEdit[0].UpdateOldDigest, instances[0]) | ||
assert.Equal(t, instancesToEdit[1].UpdateOldDigest, instances[1]) | ||
assert.Equal(t, instancesToEdit[2].UpdateOldDigest, instances[2]) | ||
|
||
// Test with CopySpecific Images | ||
copyOnly := []digest.Digest{ | ||
digest.Digest("sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), | ||
} | ||
options = Options{ | ||
Instances: copyOnly, | ||
ImageListSelection: CopySpecificImages, | ||
} | ||
instancesToEdit, imagesToCopy = prepareEditList(instances, &options) | ||
assert.Equal(t, imagesToCopy, len(copyOnly)) | ||
assert.Equal(t, instancesToEdit[0].UpdateOldDigest, copyOnly[0]) | ||
} |