test: Move temporary repo setup into test/helpers.go

This allows it to be shared between the dnf-json tests and weldrcheck.
This commit is contained in:
Brian C. Lane 2020-03-20 08:59:30 -07:00 committed by Tom Gundersen
parent 222d09499c
commit 3af34fba3f
4 changed files with 34 additions and 57 deletions

View file

@ -9,6 +9,8 @@ import (
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path"
"strings"
"testing"
"time"
@ -176,3 +178,26 @@ func IgnoreUuids() cmp.Option {
func Ignore(what string) cmp.Option {
return cmp.FilterPath(func(p cmp.Path) bool { return p.String() == what }, cmp.Ignore())
}
// Create a temporary repository
func SetUpTemporaryRepository() (string, error) {
dir, err := ioutil.TempDir("/tmp", "osbuild-composer-test-")
if err != nil {
return "", err
}
cmd := exec.Command("createrepo_c", path.Join(dir))
err = cmd.Start()
if err != nil {
return "", err
}
err = cmd.Wait()
if err != nil {
return "", err
}
return dir, nil
}
// Remove the temporary repository
func TearDownTemporaryRepository(dir string) error {
return os.RemoveAll(dir)
}