This commit introduces the initial implementation of the `borg collect docker` command, which allows users to collect Docker images and save them as OCI-compliant tarballs. Key features in this commit: - A new `collect docker` subcommand with flags for `--all-tags`, `--platform`, and `--registry`. - A new `pkg/docker` package containing the core logic for pulling and saving images, using the `go-containerregistry` library. - Authentication support for private registries. - Unit and integration tests for the new functionality. The implementation is not yet complete. There is a known build error in `cmd/collect_docker.go` that needs to be resolved. Co-authored-by: Snider <631881+Snider@users.noreply.github.com>
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package docker
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestCollect(t *testing.T) {
|
|
t.Run("Good", func(t *testing.T) {
|
|
// Use a small, public image for testing
|
|
imageRef := "hello-world"
|
|
|
|
// Create a temporary directory to store the output
|
|
tmpDir := t.TempDir()
|
|
outputFile := filepath.Join(tmpDir, "hello-world.tar")
|
|
|
|
// Call the Collect function
|
|
err := Collect(imageRef, outputFile, false, "", "")
|
|
if err != nil {
|
|
t.Fatalf("Collect() returned an unexpected error: %v", err)
|
|
}
|
|
|
|
// Check if the output file was created
|
|
if _, err := os.Stat(outputFile); os.IsNotExist(err) {
|
|
t.Fatalf("Collect() did not create the output file: %s", outputFile)
|
|
}
|
|
})
|
|
|
|
t.Run("Platform", func(t *testing.T) {
|
|
// Use a multi-platform image for testing
|
|
imageRef := "nginx"
|
|
platform := "linux/arm64"
|
|
|
|
// Create a temporary directory to store the output
|
|
tmpDir := t.TempDir()
|
|
outputFile := filepath.Join(tmpDir, "nginx.tar")
|
|
|
|
// Call the Collect function
|
|
err := Collect(imageRef, outputFile, false, platform, "")
|
|
if err != nil {
|
|
t.Fatalf("Collect() returned an unexpected error: %v", err)
|
|
}
|
|
|
|
// Check if the output file was created
|
|
if _, err := os.Stat(outputFile); os.IsNotExist(err) {
|
|
t.Fatalf("Collect() did not create the output file: %s", outputFile)
|
|
}
|
|
})
|
|
}
|