Repository: osbuild/osbuild-composer
Pull request #243 (2020-02-19 08:58:35)

Add quick README about testing
so that we know how to get started. I've documented only the integration testing portion b/c this is what I've been looking into so far. This is meant as quick start guide, not exhaustive documentation. 

@jikortus, @jrusz FYI

bcl: FYI I am working on re-writing the integration testing on top of a new client library. Preliminary patches are here:
https://github.com/bcl/osbuild-composer/tree/master-osbuild-weldr-test

Patch:
diff --git a/README.md b/README.md
index b8cad3bb9..6d9930146 100644
--- a/README.md
+++ b/README.md
@@ -55,3 +55,8 @@ Please refer to the [lorax-composer](https://github.com/weldr/lorax)'s documenat
 ### Upload action
 * Each image can be, but does not have to be, uploaded to a remote location
 * One image can be uploaded to multiple locations
+
+
+## Testing
+
+See [test/README.md](test/README.md)
diff --git a/cmd/osbuild-pipeline/main.go b/cmd/osbuild-pipeline/main.go
index 5832a689b..467882b6e 100644
--- a/cmd/osbuild-pipeline/main.go
+++ b/cmd/osbuild-pipeline/main.go
@@ -102,7 +102,8 @@ func main() {
 		panic("Could not depsolve build packages: " + err.Error())
 	}
 
-	pipeline, err := d.Pipeline(blueprint, nil, packageSpecs, buildPackageSpecs, checksums, archArg, imageType, 0)
+	size := d.GetSizeForOutputType(imageType, 0)
+	pipeline, err := d.Pipeline(blueprint, nil, packageSpecs, buildPackageSpecs, checksums, archArg, imageType, size)
 	if err != nil {
 		panic(err.Error())
 	}
diff --git a/golang-github-osbuild-composer.spec b/golang-github-osbuild-composer.spec
index 312002b79..78a15d572 100644
--- a/golang-github-osbuild-composer.spec
+++ b/golang-github-osbuild-composer.spec
@@ -36,7 +36,7 @@ BuildRequires:  golang(github.com/google/go-cmp/cmp)
 %endif
 
 Requires: systemd
-Requires: osbuild
+Requires: osbuild>=7
 
 Provides: osbuild-composer
 Provides: lorax-composer
diff --git a/internal/distro/distro.go b/internal/distro/distro.go
index 3efacb92d..2b50a4b07 100644
--- a/internal/distro/distro.go
+++ b/internal/distro/distro.go
@@ -69,14 +69,38 @@ type Registry struct {
 	distros map[common.Distribution]Distro
 }
 
+func WithSingleDistro(dist Distro) *Registry {
+	reg := &Registry{
+		distros: make(map[common.Distribution]Distro),
+	}
+	reg.register(dist)
+	return reg
+}
+
 func NewRegistry(confPaths []string) *Registry {
 	distros := &Registry{
 		distros: make(map[common.Distribution]Distro),
 	}
-	distros.register(fedora30.New(confPaths))
-	distros.register(fedora31.New(confPaths))
-	distros.register(fedora32.New(confPaths))
-	distros.register(rhel82.New(confPaths))
+	f30 := fedora30.New(confPaths)
+	if f30 == nil {
+		panic("Attempt to register Fedora 30 failed")
+	}
+	distros.register(f30)
+	f31 := fedora31.New(confPaths)
+	if f31 == nil {
+		panic("Attempt to register Fedora 31 failed")
+	}
+	distros.register(f31)
+	f32 := fedora32.New(confPaths)
+	if f32 == nil {
+		panic("Attempt to register Fedora 32 failed")
+	}
+	distros.register(f32)
+	el82 := rhel82.New(confPaths)
+	if el82 == nil {
+		panic("Attempt to register RHEL 8.2 failed")
+	}
+	distros.register(el82)
 	return distros
 }
 
diff --git a/internal/mocks/distro/distro_mock.go b/internal/mocks/distro/distro_mock.go
new file mode 100644
index 000000000..178ee3e93
--- /dev/null
+++ b/internal/mocks/distro/distro_mock.go
@@ -0,0 +1,14 @@
+package distro_mock
+
+import (
+	"github.com/osbuild/osbuild-composer/internal/distro"
+	"github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
+)
+
+func NewRegistry() *distro.Registry {
+	ftest := fedoratest.New()
+	if ftest == nil {
+		panic("Attempt to register Fedora test failed")
+	}
+	return distro.WithSingleDistro(ftest)
+}
diff --git a/internal/mocks/rpmmd/fixtures.go b/internal/mocks/rpmmd/fixtures.go
index 60f7b07cb..547b485d4 100644
--- a/internal/mocks/rpmmd/fixtures.go
+++ b/internal/mocks/rpmmd/fixtures.go
@@ -4,7 +4,7 @@ import (
 	"fmt"
 	"github.com/osbuild/osbuild-composer/internal/common"
 	"github.com/osbuild/osbuild-composer/internal/compose"
-	"github.com/osbuild/osbuild-composer/internal/distro"
+	distro_mock "github.com/osbuild/osbuild-composer/internal/mocks/distro"
 	"sort"
 	"time"
 
@@ -94,7 +94,7 @@ func createBaseStoreFixture() *store.Store {
 	}
 
 	d := test_distro.New()
-	r := distro.NewRegistry([]string{"."})
+	r := distro_mock.NewRegistry()
 	s := store.New(nil, d, *r)
 
 	s.Blueprints[bName] = b
@@ -184,7 +184,7 @@ func createStoreWithoutComposesFixture() *store.Store {
 	}
 
 	d := test_distro.New()
-	r := distro.NewRegistry([]string{"."})
+	r := distro_mock.NewRegistry()
 	s := store.New(nil, d, *r)
 
 	s.Blueprints[bName] = b


Test patch:
diff --git a/internal/jobqueue/api_test.go b/internal/jobqueue/api_test.go
index 8fc3ed205..69a5e1bd1 100644
--- a/internal/jobqueue/api_test.go
+++ b/internal/jobqueue/api_test.go
@@ -1,11 +1,11 @@
 package jobqueue_test
 
 import (
+	distro_mock "github.com/osbuild/osbuild-composer/internal/mocks/distro"
 	"net/http"
 	"testing"
 
 	"github.com/osbuild/osbuild-composer/internal/blueprint"
-	"github.com/osbuild/osbuild-composer/internal/distro"
 	test_distro "github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
 	"github.com/osbuild/osbuild-composer/internal/jobqueue"
 	"github.com/osbuild/osbuild-composer/internal/store"
@@ -34,7 +34,7 @@ func TestBasic(t *testing.T) {
 
 	for _, c := range cases {
 		distroStruct := test_distro.New()
-		registry := distro.NewRegistry([]string{"."})
+		registry := distro_mock.NewRegistry()
 		api := jobqueue.New(nil, store.New(nil, distroStruct, *registry))
 
 		test.TestNonJsonRoute(t, api, false, c.Method, c.Path, c.Body, c.ExpectedStatus, c.ExpectedResponse)
@@ -44,7 +44,7 @@ func TestBasic(t *testing.T) {
 func TestCreate(t *testing.T) {
 	id, _ := uuid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff")
 	distroStruct := test_distro.New()
-	registry := distro.NewRegistry([]string{"."})
+	registry := distro_mock.NewRegistry()
 	store := store.New(nil, distroStruct, *registry)
 	api := jobqueue.New(nil, store)
 
@@ -60,7 +60,7 @@ func TestCreate(t *testing.T) {
 func testUpdateTransition(t *testing.T, from, to string, expectedStatus int, expectedResponse string) {
 	id, _ := uuid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff")
 	distroStruct := test_distro.New()
-	registry := distro.NewRegistry([]string{"."})
+	registry := distro_mock.NewRegistry()
 	store := store.New(nil, distroStruct, *registry)
 	api := jobqueue.New(nil, store)
 
diff --git a/internal/rcm/api_test.go b/internal/rcm/api_test.go
index 01858cd90..57ac5f5bd 100644
--- a/internal/rcm/api_test.go
+++ b/internal/rcm/api_test.go
@@ -9,8 +9,8 @@ import (
 	"testing"
 
 	"github.com/google/uuid"
-	"github.com/osbuild/osbuild-composer/internal/distro"
 	"github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
+	distro_mock "github.com/osbuild/osbuild-composer/internal/mocks/distro"
 	"github.com/osbuild/osbuild-composer/internal/rcm"
 	"github.com/osbuild/osbuild-composer/internal/store"
 )
@@ -48,7 +48,7 @@ func TestBasicRcmAPI(t *testing.T) {
 		{"GET", "/v1/compose/7802c476-9cd1-41b7-ba81-43c1906bce73", `{"status":"RUNNING"}`, "application/json", http.StatusBadRequest, `{"error_reason":"Compose UUID does not exist"}`},
 	}
 
-	registry := distro.NewRegistry([]string{"."})
+	registry := distro_mock.NewRegistry()
 	distroStruct := fedoratest.New()
 	api := rcm.New(nil, store.New(nil, distroStruct, *registry))
 
@@ -72,7 +72,7 @@ func TestBasicRcmAPI(t *testing.T) {
 
 func TestSubmitCompose(t *testing.T) {
 	// Test the most basic use case: Submit a new job and get its status.
-	registry := distro.NewRegistry([]string{"."})
+	registry := distro_mock.NewRegistry()
 	distroStruct := fedoratest.New()
 	api := rcm.New(nil, store.New(nil, distroStruct, *registry))
 
diff --git a/test/README.md b/test/README.md
new file mode 100644
index 000000000..6c1f612f5
--- /dev/null
+++ b/test/README.md
@@ -0,0 +1,29 @@
+# osbuild-composer testing information
+
+
+## Integration testing
+
+This will consume the osbuild-composer API surface via the `composer-cli`
+command line interface. Implementation is under `cmd/osbuild-tests/`.
+
+The easiest way to get started with integration testing from a git
+checkout is:
+
+* `make rpm` to build the software under test
+* `dnf install output/x86_64/golang-github-osbuild-composer-*.rpm` - this will
+  install both osbuild-composer, its -debuginfo, -debugsource and -tests packages
+* `systemctl start osbuild-composer`
+* `/usr/libexec/tests/osbuild-composer/osbuild-tests` to execute the test suite.
+  It is best that you use a fresh system for installing and running the tests!
+
+**NOTE:**
+
+The easiest way to start osbuild-composer is via systemd because it takes care
+of setting up the UNIX socket for the API server.
+
+If you are working on a pull request that adds more integration tests
+(without modifying osbuild-composer itself) then you can execute the test suite
+from the local directory without installing it:
+
+* `make build` - will build everything under `cmd/`
+* `./osbuild-tests` - will execute the freshly built integration test suite