This commit adds a helper to find exactly a single image from a given disto/type/arch description. This will be used in `manifest`, `build` and potentially more. It is meant to support copy/paste from the `image-builder list-images` output, so: "distro:centos-9" is support just like "centos-9" (same for distro/imgType/arch).
54 lines
913 B
Go
54 lines
913 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/osbuild/images/pkg/reporegistry"
|
|
)
|
|
|
|
var (
|
|
GetOneImage = getOneImage
|
|
)
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
var (
|
|
Run = run
|
|
)
|