-
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 `prepareCopyInstances` which returns a list of `instanceCopy`. `prepareCopyInstances` does that in these two steps * How to copy via instanceCopyKind * 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
89 additions
and
26 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 TestPrepareCopyInstances(t *testing.T) { | ||
// Test CopyAllImages | ||
sourceInstances := []digest.Digest{ | ||
digest.Digest("sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270"), | ||
digest.Digest("sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), | ||
digest.Digest("sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"), | ||
} | ||
|
||
instancesToCopy := prepareInstanceCopies(sourceInstances, &Options{}) | ||
compare := []instanceCopy{} | ||
for _, instance := range sourceInstances { | ||
compare = append(compare, instanceCopy{op: instanceCopyCopy, | ||
sourceDigest: instance}) | ||
} | ||
assert.Equal(t, instancesToCopy, compare) | ||
|
||
// Test with CopySpecific Images | ||
copyOnly := []digest.Digest{ | ||
digest.Digest("sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), | ||
} | ||
instancesToCopy = prepareInstanceCopies(sourceInstances, &Options{ | ||
Instances: copyOnly, | ||
ImageListSelection: CopySpecificImages}) | ||
assert.Equal(t, instancesToCopy, []instanceCopy{{ | ||
op: instanceCopyCopy, | ||
sourceDigest: copyOnly[0]}}) | ||
} |