Skip to content

[WIP] POC: Rewrite dnf-json integration tests for go test #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ __pycache__

/osbuild-composer
/osbuild-worker
/osbuild-weldr-tests
/osbuild-pipeline
/osbuild-upload-azure
/osbuild-upload-aws
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build:
go build -o osbuild-upload-aws ./cmd/osbuild-upload-aws/
go build -o osbuild-tests ./cmd/osbuild-tests/
go build -o osbuild-weldr-tests ./cmd/osbuild-weldr-tests/
go build -o osbuild-dnf-json-tests ./cmd/osbuild-dnf-json-tests/
go test -c -o osbuild-dnf-json-tests ./cmd/osbuild-dnf-json-tests/main_test.go
go build -o osbuild-rcm-tests ./cmd/osbuild-rcm-tests/

.PHONY: install
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
// +build integration

// 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"
"testing"
"path"
)

func main() {
// Tests that the package wrapping dnf-json works as expected
dir, err := setUpTemporaryRepository()
defer func(dir string) {
err := tearDownTemporaryRepository(dir)
if err != nil {
log.Print("Warning: failed to clean up temporary repository.")
}
}(dir)
if err != nil {
log.Panic("Failed to set up temporary repository:", err)
}
TestFetchChecksum(false, dir)
}

func setUpTemporaryRepository() (string, error) {
dir, err := ioutil.TempDir("/tmp", "osbuild-composer-test-")
if err != nil {
Expand All @@ -47,25 +34,30 @@ func tearDownTemporaryRepository(dir string) error {
return os.RemoveAll(dir)
}

func TestFetchChecksum(quiet bool, dir string) {
func TestFetchChecksum(t *testing.T) {
dir, err := setUpTemporaryRepository()
defer func(dir string) {
err := tearDownTemporaryRepository(dir)
if err != nil {
t.Errorf("Warning: failed to clean up temporary repository.")
}
}(dir)
if err != nil {
t.Errorf("Failed to set up temporary repository: %s", err)
}

repoCfg := rpmmd.RepoConfig{
Id: "repo",
Name: "repo",
BaseURL: fmt.Sprintf("file://%s", dir),
IgnoreSSL: true,
}
if !quiet {
log.Println("Running TestFetchChecksum on:", dir)
}
rpmMetadata := rpmmd.NewRPMMD(path.Join(dir, "rpmmd"))
_, c, err := rpmMetadata.FetchMetadata([]rpmmd.RepoConfig{repoCfg}, "platform:f31")
if err != nil {
log.Panic("Failed to fetch checksum:", err)
t.Errorf("Failed to fetch checksum: %s", err)
}
if c["repo"] == "" {
log.Panic("The checksum is empty")
}
if !quiet {
log.Println("TestFetchChecksum: SUCCESS")
t.Errorf("The checksum is empty")
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/google/uuid v1.1.1
github.com/julienschmidt/httprouter v1.2.0
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.4.0 // indirect
github.com/stretchr/testify v1.4.0
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect
)
4 changes: 3 additions & 1 deletion golang-github-osbuild-composer.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
%global goipath github.com/osbuild/osbuild-composer
# workaround for https://pagure.io/go-rpm-macros/pull-request/23
%define gotest_co(c:o:) GO111MODULE=off go test %{gotestflags} -ldflags "${LDFLAGS:-}%{?currentgoldflags} -extldflags '%{gotestextldflags}'" %{?**};

Version: 7

Expand Down Expand Up @@ -68,7 +70,7 @@ export GOFLAGS=-mod=vendor
%gobuild -o _bin/osbuild-worker %{goipath}/cmd/osbuild-worker
%gobuild -o _bin/osbuild-tests %{goipath}/cmd/osbuild-tests
%gobuild -o _bin/osbuild-weldr-tests %{goipath}/cmd/osbuild-weldr-tests
%gobuild -o _bin/osbuild-dnf-json-tests %{goipath}/cmd/osbuild-dnf-json-tests
%gotest_co -c -o _bin/osbuild-dnf-json-tests %{goipath}/cmd/osbuild-dnf-json-tests
%gobuild -o _bin/osbuild-image-tests %{goipath}/cmd/osbuild-image-tests

%install
Expand Down