Skip to content

Commit 3ef8ccb

Browse files
committed
Tests: remove fedoratest and replace it with test_distro
fedoratest was yet another dummy distribution used by unit tests. After the rework of test_distro, there is no reason to not use it as the only distro implementation for testing purposes. Remove fedoratest distro and replace it with test_distro in all affected tests. Signed-off-by: Tomas Hozza <[email protected]>
1 parent 452e7b3 commit 3ef8ccb

File tree

11 files changed

+151
-270
lines changed

11 files changed

+151
-270
lines changed

internal/client/compose_test.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package client
2222

2323
import (
24+
"fmt"
2425
"io/ioutil"
2526
"net/http"
2627
"testing"
@@ -40,12 +41,12 @@ func TestComposeTypesV0(t *testing.T) {
4041
require.Greater(t, len(composeTypes), 0)
4142
var found bool
4243
for _, t := range composeTypes {
43-
if t.Name == "qcow2" && t.Enabled == true {
44+
if t.Name == testState.imageTypeName && t.Enabled == true {
4445
found = true
4546
break
4647
}
4748
}
48-
require.True(t, found, "qcow2 not in list of compose types: %#v", composeTypes)
49+
require.True(t, found, "%s not in list of compose types: %#v", testState.imageTypeName, composeTypes)
4950
}
5051

5152
// Test compose with invalid type fails
@@ -76,11 +77,11 @@ func TestComposeInvalidTypeV0(t *testing.T) {
7677

7778
// Test compose for unknown blueprint fails
7879
func TestComposeInvalidBlueprintV0(t *testing.T) {
79-
compose := `{
80+
compose := fmt.Sprintf(`{
8081
"blueprint_name": "test-invalid-bp-compose-v0",
81-
"compose_type": "qcow2",
82+
"compose_type": "%s",
8283
"branch": "master"
83-
}`
84+
}`, testState.imageTypeName)
8485
resp, err := PostComposeV0(testState.socket, compose)
8586
require.NoError(t, err, "failed with a client error")
8687
require.NotNil(t, resp)
@@ -91,11 +92,11 @@ func TestComposeInvalidBlueprintV0(t *testing.T) {
9192

9293
// Test compose for empty blueprint fails
9394
func TestComposeEmptyBlueprintV0(t *testing.T) {
94-
compose := `{
95+
compose := fmt.Sprintf(`{
9596
"blueprint_name": "",
96-
"compose_type": "qcow2",
97+
"compose_type": "%s",
9798
"branch": "master"
98-
}`
99+
}`, testState.imageTypeName)
99100
resp, err := PostComposeV0(testState.socket, compose)
100101
require.NoError(t, err, "failed with a client error")
101102
require.NotNil(t, resp)
@@ -106,11 +107,11 @@ func TestComposeEmptyBlueprintV0(t *testing.T) {
106107

107108
// Test compose for blueprint with invalid characters fails
108109
func TestComposeInvalidCharsBlueprintV0(t *testing.T) {
109-
compose := `{
110+
compose := fmt.Sprintf(`{
110111
"blueprint_name": "I w𝒊ll 𝟉ο𝘁 𝛠a𝔰ꜱ 𝘁𝒉𝝸𝚜",
111-
"compose_type": "qcow2",
112+
"compose_type": "%s",
112113
"branch": "master"
113-
}`
114+
}`, testState.imageTypeName)
114115
resp, err := PostComposeV0(testState.socket, compose)
115116
require.NoError(t, err, "failed with a client error")
116117
require.NotNil(t, resp)
@@ -283,11 +284,11 @@ func TestFailedComposeV0(t *testing.T) {
283284
require.NoError(t, err, "failed with a client error")
284285
require.True(t, resp.Status, "POST failed: %#v", resp)
285286

286-
compose := `{
287+
compose := fmt.Sprintf(`{
287288
"blueprint_name": "test-failed-compose-v0",
288-
"compose_type": "qcow2",
289+
"compose_type": "%s",
289290
"branch": "master"
290-
}`
291+
}`, testState.imageTypeName)
291292
// Create a failed test compose
292293
body, resp, err := PostJSON(testState.socket, "/api/v1/compose?test=1", compose)
293294
require.NoError(t, err, "failed with a client error")
@@ -378,11 +379,11 @@ func TestFinishedComposeV0(t *testing.T) {
378379
require.NoError(t, err, "failed with a client error")
379380
require.True(t, resp.Status, "POST failed: %#v", resp)
380381

381-
compose := `{
382+
compose := fmt.Sprintf(`{
382383
"blueprint_name": "test-finished-compose-v0",
383-
"compose_type": "qcow2",
384+
"compose_type": "%s",
384385
"branch": "master"
385-
}`
386+
}`, testState.imageTypeName)
386387
// Create a finished test compose
387388
body, resp, err := PostJSON(testState.socket, "/api/v1/compose?test=2", compose)
388389
require.NoError(t, err, "failed with a client error")

internal/client/integration_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ var testState *TestState
2020
// Also makes sure there is a running server to test against
2121
func executeTests(m *testing.M) int {
2222
var err error
23-
testState, err = setUpTestState("/run/weldr/api.socket", false)
23+
24+
testState, err = setUpTestState("/run/weldr/api.socket", "qcow2", false)
2425
if err != nil {
2526
fmt.Printf("ERROR: Test setup failed: %s\n", err)
2627
panic(err)

internal/client/unit_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"path"
1515
"testing"
1616

17-
"github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
17+
"github.com/osbuild/osbuild-composer/internal/distro/test_distro"
1818
rpmmd_mock "github.com/osbuild/osbuild-composer/internal/mocks/rpmmd"
1919
"github.com/osbuild/osbuild-composer/internal/rpmmd"
2020
"github.com/osbuild/osbuild-composer/internal/weldr"
@@ -44,8 +44,8 @@ func executeTests(m *testing.M) int {
4444
}
4545
fixture := rpmmd_mock.BaseFixture(path.Join(tmpdir, "/jobs"))
4646
rpm := rpmmd_mock.NewRPMMDMock(fixture)
47-
distro := fedoratest.New()
48-
arch, err := distro.GetArch("x86_64")
47+
distro := test_distro.New()
48+
arch, err := distro.GetArch(test_distro.TestArchName)
4949
if err != nil {
5050
panic(err)
5151
}
@@ -62,7 +62,7 @@ func executeTests(m *testing.M) int {
6262
}
6363
}()
6464

65-
testState, err = setUpTestState(socketPath, true)
65+
testState, err = setUpTestState(socketPath, test_distro.TestImageTypeName, true)
6666
if err != nil {
6767
log.Fatalf("ERROR: Test setup failed: %s\n", err)
6868
}

internal/client/utils.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import (
1414
)
1515

1616
type TestState struct {
17-
socket *http.Client
18-
apiVersion int
19-
repoDir string
20-
unitTest bool
17+
socket *http.Client
18+
apiVersion int
19+
repoDir string
20+
unitTest bool
21+
imageTypeName string
2122
}
2223

2324
// isStringInSlice returns true if the string is present, false if not
@@ -31,8 +32,8 @@ func isStringInSlice(slice []string, s string) bool {
3132
return false
3233
}
3334

34-
func setUpTestState(socketPath string, unitTest bool) (*TestState, error) {
35-
state := TestState{unitTest: unitTest}
35+
func setUpTestState(socketPath string, imageTypeName string, unitTest bool) (*TestState, error) {
36+
state := TestState{imageTypeName: imageTypeName, unitTest: unitTest}
3637

3738
state.socket = &http.Client{
3839
Transport: &http.Transport{

internal/distro/fedoratest/distro.go

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)