osbuild-tests: create repository test
this test will create a temporary directory, create repo inside, then fetch the checksum, and finally clean up the directory
This commit is contained in:
parent
4c7b52ce2f
commit
251d63c06a
2 changed files with 70 additions and 0 deletions
66
cmd/osbuild-dnf-json-tests/main.go
Normal file
66
cmd/osbuild-dnf-json-tests/main.go
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
// This package contains tests related to dnf-json and rpmmd package.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Tests that the package wrapping dnf-json works as expected
|
||||
dir, err := setUpTemporaryRepository()
|
||||
if err != nil {
|
||||
log.Fatal("Failed to set up temporary repository:", err)
|
||||
}
|
||||
TestFetchChecksum(false, dir)
|
||||
err = tearDownTemporaryRepository(dir)
|
||||
if err != nil {
|
||||
log.Print("Warning: failed to clean up 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
|
||||
}
|
||||
|
||||
func tearDownTemporaryRepository(dir string) error {
|
||||
return os.RemoveAll(dir)
|
||||
}
|
||||
|
||||
func TestFetchChecksum(quiet bool, dir string) {
|
||||
repoCfg := rpmmd.RepoConfig{
|
||||
Id: "repo",
|
||||
Name: "repo",
|
||||
BaseURL: fmt.Sprintf("file://%s", dir),
|
||||
IgnoreSSL: true,
|
||||
}
|
||||
if !quiet {
|
||||
log.Println("Running TestFetchChecksum on:", dir)
|
||||
}
|
||||
c, err := repoCfg.FetchChecksum()
|
||||
if err != nil {
|
||||
log.Fatal("Failed to fetch checksum:", err)
|
||||
}
|
||||
if c == "" {
|
||||
log.Fatal("The checksum is empty")
|
||||
}
|
||||
log.Println("SUCCESS")
|
||||
}
|
||||
|
|
@ -65,6 +65,7 @@ export GOFLAGS=-mod=vendor
|
|||
%gobuild -o _bin/osbuild-composer %{goipath}/cmd/osbuild-composer
|
||||
%gobuild -o _bin/osbuild-worker %{goipath}/cmd/osbuild-worker
|
||||
%gobuild -o _bin/osbuild-tests %{goipath}/cmd/osbuild-tests
|
||||
%gobuild -o _bin/osbuild-dnf-json-tests %{goipath}/cmd/osbuild-dnf-json-tests
|
||||
|
||||
%install
|
||||
install -m 0755 -vd %{buildroot}%{_libexecdir}/osbuild-composer
|
||||
|
|
@ -74,6 +75,7 @@ install -m 0755 -vp dnf-json %{buildroot}%{_libex
|
|||
|
||||
install -m 0755 -vd %{buildroot}%{_libexecdir}/tests/osbuild-composer
|
||||
install -m 0755 -vp _bin/osbuild-tests %{buildroot}%{_libexecdir}/tests/osbuild-composer/
|
||||
install -m 0755 -vp _bin/osbuild-dnf-json-tests %{buildroot}%{_libexecdir}/tests/osbuild-composer/
|
||||
|
||||
install -m 0755 -vd %{buildroot}%{_datadir}/osbuild-composer/repositories
|
||||
install -m 0644 -vp repositories/* %{buildroot}%{_datadir}/osbuild-composer/repositories/
|
||||
|
|
@ -116,12 +118,14 @@ export GOPATH=$PWD/_build:%{gopath}
|
|||
Summary: Integration tests
|
||||
Requires: osbuild-composer
|
||||
Requires: composer-cli
|
||||
Requires: createrepo_c
|
||||
|
||||
%description tests
|
||||
Integration tests to be run on a pristine-dedicated system to test the osbuild-composer package.
|
||||
|
||||
%files tests
|
||||
%{_libexecdir}/tests/osbuild-composer/osbuild-tests
|
||||
%{_libexecdir}/tests/osbuild-composer/osbuild-dnf-json-tests
|
||||
|
||||
%changelog
|
||||
* Sun Dec 1 11:00:00 CEST 2019 Ondrej Budai <obudai@redhat.com> - 4-1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue