debian-forge-cli/cmd/image-builder/export_test.go
Michael Vogt e41377b82a main: add new upload command
This commit adds a new `upload` command that can be used to
upload a raw image to the cloud. Currently only AWS is
supported but as images adds more clouds to the uploader interfac
we can easily expand more.

The cloud is currently detected via the file extension, that
mapping probably should also go into the `images` library.
2025-02-11 13:38:04 +01:00

72 lines
1.5 KiB
Go

package main
import (
"fmt"
"io"
"os"
"github.com/osbuild/images/pkg/cloud"
"github.com/osbuild/images/pkg/cloud/awscloud"
"github.com/osbuild/images/pkg/reporegistry"
)
var (
GetOneImage = getOneImage
Run = run
FindDistro = findDistro
DescribeImage = describeImage
ProgressFromCmd = progressFromCmd
)
func MockOsArgs(new []string) (restore func()) {
saved := os.Args
os.Args = append([]string{"argv0"}, new...)
return func() {
os.Args = saved
}
}
func MockOsStdout(new io.Writer) (restore func()) {
saved := osStdout
osStdout = new
return func() {
osStdout = saved
}
}
func MockOsStderr(new io.Writer) (restore func()) {
saved := osStderr
osStderr = new
return func() {
osStderr = saved
}
}
func MockNewRepoRegistry(f func() (*reporegistry.RepoRegistry, error)) (restore func()) {
saved := newRepoRegistry
newRepoRegistry = func(dataDir string) (*reporegistry.RepoRegistry, error) {
if dataDir != "" {
panic(fmt.Sprintf("cannot use custom dataDir %v in mock", dataDir))
}
return f()
}
return func() {
newRepoRegistry = saved
}
}
func MockDistroGetHostDistroName(f func() (string, error)) (restore func()) {
saved := distroGetHostDistroName
distroGetHostDistroName = f
return func() {
distroGetHostDistroName = saved
}
}
func MockAwscloudNewUploader(f func(string, string, string, *awscloud.UploaderOptions) (cloud.Uploader, error)) (restore func()) {
saved := awscloudNewUploader
awscloudNewUploader = f
return func() {
awscloudNewUploader = saved
}
}