client: Move the weldrcheck integration tests to client
With this change the integration tests can now also be run as unit tests against the mocked server. The way it works is this: internal/client/unit_test.go sets up the mock server and is built when the `integration` build tag is *not* included. internal/client/integration_test.go sets up the connection to an existing server and is built when the `integration` build tag *is* included. The test code is built and run for both cases. Currently they all pass for the integration test run. The unit test cases need some work because the mocked server isn't a real server with real depsolving and package lists. A future commit will fix this.
This commit is contained in:
parent
816a09fd9d
commit
856eb59edf
9 changed files with 101 additions and 225 deletions
2
Makefile
2
Makefile
|
|
@ -8,7 +8,7 @@ build:
|
|||
go build -o osbuild-upload-azure ./cmd/osbuild-upload-azure/
|
||||
go build -o osbuild-upload-aws ./cmd/osbuild-upload-aws/
|
||||
go test -c -tags=integration -o osbuild-tests ./cmd/osbuild-tests/main_test.go
|
||||
go test -c -tags=integration -o osbuild-weldr-tests ./internal/weldrcheck/
|
||||
go test -c -tags=integration -o osbuild-weldr-tests ./internal/client/
|
||||
go test -c -tags=integration -o osbuild-dnf-json-tests ./cmd/osbuild-dnf-json-tests/main_test.go
|
||||
go test -c -tags=integration -o osbuild-rcm-tests ./cmd/osbuild-rcm-tests/main_test.go
|
||||
go test -c -tags=integration,travis -o osbuild-image-tests ./cmd/osbuild-image-tests/
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ TEST_LDFLAGS="${LDFLAGS:-} -B 0x$(od -N 20 -An -tx1 -w100 /dev/urandom | tr -d '
|
|||
|
||||
go test -c -tags=integration -ldflags="${TEST_LDFLAGS}" -o _bin/osbuild-tests %{goipath}/cmd/osbuild-tests
|
||||
go test -c -tags=integration -ldflags="${TEST_LDFLAGS}" -o _bin/osbuild-dnf-json-tests %{goipath}/cmd/osbuild-dnf-json-tests
|
||||
go test -c -tags=integration -ldflags="${TEST_LDFLAGS}" -o _bin/osbuild-weldr-tests %{goipath}/internal/weldrcheck/
|
||||
go test -c -tags=integration -ldflags="${TEST_LDFLAGS}" -o _bin/osbuild-weldr-tests %{goipath}/internal/client/
|
||||
go test -c -tags=integration -ldflags="${TEST_LDFLAGS}" -o _bin/osbuild-rcm-tests %{goipath}/cmd/osbuild-rcm-tests
|
||||
go test -c -tags=integration -ldflags="${TEST_LDFLAGS}" -o _bin/osbuild-image-tests %{goipath}/cmd/osbuild-image-tests
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Package weldrcheck - blueprints contains functions to check the blueprints API
|
||||
// Package client - blueprints_test contains functions to check the blueprints API
|
||||
// Copyright (C) 2020 by Red Hat, Inc.
|
||||
|
||||
// Tests should be self-contained and not depend on the state of the server
|
||||
|
|
@ -8,57 +8,16 @@
|
|||
// not from other functions.
|
||||
// The blueprint version number may get bumped if the server has had tests run before
|
||||
// do not assume the bp version will match unless first deleting the old one.
|
||||
|
||||
// +build integration
|
||||
|
||||
package weldrcheck
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/client"
|
||||
"github.com/osbuild/osbuild-composer/internal/test"
|
||||
)
|
||||
|
||||
// Hold test state to share between tests
|
||||
var testState *TestState
|
||||
|
||||
// Setup the socket to use for running the tests
|
||||
// Also makes sure there is a running server to test against
|
||||
func TestMain(m *testing.M) {
|
||||
var err error
|
||||
testState, err = setUpTestState("/run/weldr/api.socket", 60*time.Second)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: Test setup failed: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Setup the test repo
|
||||
dir, err := test.SetUpTemporaryRepository()
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: Test repo setup failed: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
testState.repoDir = dir
|
||||
|
||||
// Run the tests
|
||||
rc := m.Run()
|
||||
|
||||
// Cleanup after the tests
|
||||
err = test.TearDownTemporaryRepository(dir)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: Failed to clean up temporary repository: %s\n", err)
|
||||
}
|
||||
os.Exit(rc)
|
||||
}
|
||||
|
||||
// POST a new TOML blueprint
|
||||
func TestPostTOMLBlueprintV0(t *testing.T) {
|
||||
bp := `
|
||||
|
|
@ -77,7 +36,7 @@ func TestPostTOMLBlueprintV0(t *testing.T) {
|
|||
name="root"
|
||||
password="qweqweqwe"
|
||||
`
|
||||
resp, err := client.PostTOMLBlueprintV0(testState.socket, bp)
|
||||
resp, err := PostTOMLBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.True(t, resp.Status, "POST failed: %#v", resp)
|
||||
}
|
||||
|
|
@ -92,14 +51,14 @@ func TestPostInvalidTOMLBlueprintV0(t *testing.T) {
|
|||
name="bash"
|
||||
version="*"
|
||||
`
|
||||
resp, err := client.PostTOMLBlueprintV0(testState.socket, bp)
|
||||
resp, err := PostTOMLBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
||||
// POST an empty TOML blueprint
|
||||
func TestPostEmptyTOMLBlueprintV0(t *testing.T) {
|
||||
resp, err := client.PostTOMLBlueprintV0(testState.socket, "")
|
||||
resp, err := PostTOMLBlueprintV0(testState.socket, "")
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
|
@ -115,7 +74,7 @@ func TestPostJSONBlueprintV0(t *testing.T) {
|
|||
"customizations": {"user": [{"name": "root", "password": "qweqweqwe"}]}
|
||||
}`
|
||||
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bp)
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.True(t, resp.Status, "POST failed: %#v", resp)
|
||||
}
|
||||
|
|
@ -129,14 +88,14 @@ func TestPostInvalidJSONBlueprintV0(t *testing.T) {
|
|||
"modules": [{"name: "util-linux", "version": "*"}],
|
||||
}`
|
||||
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bp)
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
||||
// POST an empty JSON blueprint
|
||||
func TestPostEmptyJSONBlueprintV0(t *testing.T) {
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, "")
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, "")
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
|
@ -159,7 +118,7 @@ func TestPostTOMLWorkspaceV0(t *testing.T) {
|
|||
name="root"
|
||||
password="qweqweqwe"
|
||||
`
|
||||
resp, err := client.PostTOMLWorkspaceV0(testState.socket, bp)
|
||||
resp, err := PostTOMLWorkspaceV0(testState.socket, bp)
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.True(t, resp.Status, "POST failed: %#v", resp)
|
||||
}
|
||||
|
|
@ -174,14 +133,14 @@ func TestPostInvalidTOMLWorkspaceV0(t *testing.T) {
|
|||
name="bash"
|
||||
version="*"
|
||||
`
|
||||
resp, err := client.PostTOMLWorkspaceV0(testState.socket, bp)
|
||||
resp, err := PostTOMLWorkspaceV0(testState.socket, bp)
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
||||
// POST an empty TOML blueprint to the workspace
|
||||
func TestPostEmptyTOMLWorkspaceV0(t *testing.T) {
|
||||
resp, err := client.PostTOMLWorkspaceV0(testState.socket, "")
|
||||
resp, err := PostTOMLWorkspaceV0(testState.socket, "")
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
|
@ -197,7 +156,7 @@ func TestPostJSONWorkspaceV0(t *testing.T) {
|
|||
"customizations": {"user": [{"name": "root", "password": "qweqweqwe"}]}
|
||||
}`
|
||||
|
||||
resp, err := client.PostJSONWorkspaceV0(testState.socket, bp)
|
||||
resp, err := PostJSONWorkspaceV0(testState.socket, bp)
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.True(t, resp.Status, "POST failed: %#v", resp)
|
||||
}
|
||||
|
|
@ -211,14 +170,14 @@ func TestPostInvalidJSONWorkspaceV0(t *testing.T) {
|
|||
"modules": [{"name: "util-linux", "version": "*"}],
|
||||
}`
|
||||
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bp)
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
||||
// POST an empty JSON blueprint to the workspace
|
||||
func TestPostEmptyJSONWorkspaceV0(t *testing.T) {
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, "")
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, "")
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
|
@ -235,19 +194,19 @@ func TestDeleteBlueprintV0(t *testing.T) {
|
|||
"customizations": {"user": [{"name": "root", "password": "qweqweqwe"}]}
|
||||
}`
|
||||
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bp)
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.True(t, resp.Status, "POST failed: %#v", resp)
|
||||
|
||||
// Delete the blueprint
|
||||
resp, err = client.DeleteBlueprintV0(testState.socket, "test-delete-blueprint-v0")
|
||||
resp, err = DeleteBlueprintV0(testState.socket, "test-delete-blueprint-v0")
|
||||
require.NoError(t, err, "DELETE failed with a client error")
|
||||
require.True(t, resp.Status, "DELETE failed: %#v", resp)
|
||||
}
|
||||
|
||||
// delete a non-existent blueprint
|
||||
func TestDeleteNonBlueprint0(t *testing.T) {
|
||||
resp, err := client.DeleteBlueprintV0(testState.socket, "test-delete-non-blueprint-v0")
|
||||
resp, err := DeleteBlueprintV0(testState.socket, "test-delete-non-blueprint-v0")
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
|
@ -264,12 +223,12 @@ func TestDeleteNewWorkspaceV0(t *testing.T) {
|
|||
"customizations": {"user": [{"name": "root", "password": "qweqweqwe"}]}
|
||||
}`
|
||||
|
||||
resp, err := client.PostJSONWorkspaceV0(testState.socket, bp)
|
||||
resp, err := PostJSONWorkspaceV0(testState.socket, bp)
|
||||
require.NoError(t, err, "POST failed with a client error")
|
||||
require.True(t, resp.Status, "POST failed: %#v", resp)
|
||||
|
||||
// Delete the blueprint
|
||||
resp, err = client.DeleteWorkspaceV0(testState.socket, "test-delete-new-blueprint-ws-v0")
|
||||
resp, err = DeleteWorkspaceV0(testState.socket, "test-delete-new-blueprint-ws-v0")
|
||||
require.NoError(t, err, "DELETE failed with a client error")
|
||||
require.True(t, resp.Status, "DELETE failed: %#v", resp)
|
||||
}
|
||||
|
|
@ -286,7 +245,7 @@ func TestDeleteChangesWorkspaceV0(t *testing.T) {
|
|||
"customizations": {"user": [{"name": "root", "password": "qweqweqwe"}]}
|
||||
}`
|
||||
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bp)
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "POST blueprint failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint failed: %#v", resp)
|
||||
|
||||
|
|
@ -300,12 +259,12 @@ func TestDeleteChangesWorkspaceV0(t *testing.T) {
|
|||
"customizations": {"user": [{"name": "root", "password": "qweqweqwe"}]}
|
||||
}`
|
||||
|
||||
resp, err = client.PostJSONWorkspaceV0(testState.socket, bp)
|
||||
resp, err = PostJSONWorkspaceV0(testState.socket, bp)
|
||||
require.NoError(t, err, "POST workspace failed with a client error")
|
||||
require.True(t, resp.Status, "POST workspace failed: %#v", resp)
|
||||
|
||||
// Get the blueprint, make sure it is the modified one and that changes = true
|
||||
info, api, err := client.GetBlueprintsInfoJSONV0(testState.socket, "test-delete-blueprint-changes-ws-v0")
|
||||
info, api, err := GetBlueprintsInfoJSONV0(testState.socket, "test-delete-blueprint-changes-ws-v0")
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "GET blueprint request failed: %#v", api)
|
||||
require.Greater(t, len(info.Blueprints), 0, "No blueprints returned")
|
||||
|
|
@ -316,12 +275,12 @@ func TestDeleteChangesWorkspaceV0(t *testing.T) {
|
|||
require.Equal(t, "workspace copy", info.Blueprints[0].Description, "workspace copy not returned")
|
||||
|
||||
// Delete the blueprint from the workspace
|
||||
resp, err = client.DeleteWorkspaceV0(testState.socket, "test-delete-blueprint-changes-ws-v0")
|
||||
resp, err = DeleteWorkspaceV0(testState.socket, "test-delete-blueprint-changes-ws-v0")
|
||||
require.NoError(t, err, "DELETE workspace failed with a client error")
|
||||
require.True(t, resp.Status, "DELETE workspace failed: %#v", resp)
|
||||
|
||||
// Get the blueprint, make sure it is the un-modified one
|
||||
info, api, err = client.GetBlueprintsInfoJSONV0(testState.socket, "test-delete-blueprint-changes-ws-v0")
|
||||
info, api, err = GetBlueprintsInfoJSONV0(testState.socket, "test-delete-blueprint-changes-ws-v0")
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "GET blueprint request failed: %#v", api)
|
||||
require.Greater(t, len(info.Blueprints), 0, "No blueprints returned")
|
||||
|
|
@ -353,13 +312,13 @@ func TestListBlueprintsV0(t *testing.T) {
|
|||
}`}
|
||||
|
||||
for i := range bps {
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bps[i])
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bps[i])
|
||||
require.NoError(t, err, "POST blueprint failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint failed: %#v", resp)
|
||||
}
|
||||
|
||||
// Get the list of blueprints
|
||||
list, api, err := client.ListBlueprintsV0(testState.socket)
|
||||
list, api, err := ListBlueprintsV0(testState.socket)
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "ListBlueprints failed: %#v", api)
|
||||
require.Contains(t, list, "test-list-blueprint-1-v0")
|
||||
|
|
@ -378,12 +337,12 @@ func TestGetTOMLBlueprintV0(t *testing.T) {
|
|||
}`
|
||||
|
||||
// Post a blueprint
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bp)
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "POST blueprint failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint failed: %#v", resp)
|
||||
|
||||
// Get it as TOML
|
||||
body, api, err := client.GetBlueprintInfoTOMLV0(testState.socket, "test-get-blueprint-1-v0")
|
||||
body, api, err := GetBlueprintInfoTOMLV0(testState.socket, "test-get-blueprint-1-v0")
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "GetBlueprintInfoTOML failed: %#v", api)
|
||||
require.Greater(t, len(body), 0, "body of response is empty")
|
||||
|
|
@ -396,7 +355,7 @@ func TestGetTOMLBlueprintV0(t *testing.T) {
|
|||
|
||||
// get non-existent blueprint contents as TOML
|
||||
func TestGetNonTOMLBlueprintV0(t *testing.T) {
|
||||
_, api, err := client.GetBlueprintInfoTOMLV0(testState.socket, "test-get-non-blueprint-1-v0")
|
||||
_, api, err := GetBlueprintInfoTOMLV0(testState.socket, "test-get-non-blueprint-1-v0")
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.NotNil(t, api, "did not return an error")
|
||||
require.False(t, api.Status, "wrong Status (true)")
|
||||
|
|
@ -414,12 +373,12 @@ func TestGetJSONBlueprintV0(t *testing.T) {
|
|||
}`
|
||||
|
||||
// Post a blueprint
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bp)
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "POST blueprint failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint failed: %#v", resp)
|
||||
|
||||
// Get the blueprint and its changed state
|
||||
info, api, err := client.GetBlueprintsInfoJSONV0(testState.socket, "test-get-blueprint-2-v0")
|
||||
info, api, err := GetBlueprintsInfoJSONV0(testState.socket, "test-get-blueprint-2-v0")
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "GetBlueprintInfoJSON failed: %#v", api)
|
||||
require.Greater(t, len(info.Blueprints), 0, "No blueprints returned")
|
||||
|
|
@ -431,7 +390,7 @@ func TestGetJSONBlueprintV0(t *testing.T) {
|
|||
|
||||
// get non-existent blueprint contents as JSON
|
||||
func TestGetNonJSONBkueprintV0(t *testing.T) {
|
||||
resp, api, err := client.GetBlueprintsInfoJSONV0(testState.socket, "test-get-non-blueprint-1-v0")
|
||||
resp, api, err := GetBlueprintsInfoJSONV0(testState.socket, "test-get-non-blueprint-1-v0")
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "ListBlueprints failed: %#v", api)
|
||||
require.Greater(t, len(resp.Errors), 0, "failed with no error: %#v", resp)
|
||||
|
|
@ -449,7 +408,7 @@ func TestBumpBlueprintVersionV0(t *testing.T) {
|
|||
}`
|
||||
|
||||
// List blueprints
|
||||
list, api, err := client.ListBlueprintsV0(testState.socket)
|
||||
list, api, err := ListBlueprintsV0(testState.socket)
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "ListBlueprints failed: %#v", api)
|
||||
|
||||
|
|
@ -457,23 +416,23 @@ func TestBumpBlueprintVersionV0(t *testing.T) {
|
|||
sorted := sort.StringSlice(list)
|
||||
if isStringInSlice(sorted, "test-bump-blueprint-1-v0") {
|
||||
// Delete this blueprint if it already exists
|
||||
resp, err := client.DeleteBlueprintV0(testState.socket, "test-bump-blueprint-1-v0")
|
||||
resp, err := DeleteBlueprintV0(testState.socket, "test-bump-blueprint-1-v0")
|
||||
require.NoError(t, err, "DELETE blueprint failed with a client error")
|
||||
require.True(t, resp.Status, "DELETE blueprint failed: %#v", resp)
|
||||
}
|
||||
|
||||
// Post a blueprint
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bp)
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "POST blueprint failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint failed: %#v", resp)
|
||||
|
||||
// Post a blueprint again to bump verion to 2.1.3
|
||||
resp, err = client.PostJSONBlueprintV0(testState.socket, bp)
|
||||
resp, err = PostJSONBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "POST blueprint 2nd time failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint 2nd time failed: %#v", resp)
|
||||
|
||||
// Get the blueprint and its changed state
|
||||
info, api, err := client.GetBlueprintsInfoJSONV0(testState.socket, "test-bump-blueprint-1-v0")
|
||||
info, api, err := GetBlueprintsInfoJSONV0(testState.socket, "test-bump-blueprint-1-v0")
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "GetBlueprintsInfoJSON failed: %#v", api)
|
||||
require.Greater(t, len(info.Blueprints), 0, "No blueprints returned")
|
||||
|
|
@ -509,13 +468,13 @@ func TestBlueprintChangesV0(t *testing.T) {
|
|||
|
||||
// Push 3 changes to the blueprint
|
||||
for i := range bps {
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bps[i])
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bps[i])
|
||||
require.NoError(t, err, "POST blueprint #%d failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint #%d failed: %#v", i, resp)
|
||||
}
|
||||
|
||||
// List the changes
|
||||
changes, api, err := client.GetBlueprintsChangesV0(testState.socket, []string{"test-blueprint-changes-v0"})
|
||||
changes, api, err := GetBlueprintsChangesV0(testState.socket, []string{"test-blueprint-changes-v0"})
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "GetBlueprintsChanges failed: %#v", api)
|
||||
require.Equal(t, 1, len(changes.BlueprintsChanges), "No changes returned")
|
||||
|
|
@ -525,7 +484,7 @@ func TestBlueprintChangesV0(t *testing.T) {
|
|||
|
||||
// Get changes for a non-existent blueprint
|
||||
func TestBlueprintNonChangesV0(t *testing.T) {
|
||||
resp, api, err := client.GetBlueprintsChangesV0(testState.socket, []string{"test-non-blueprint-changes-v0"})
|
||||
resp, api, err := GetBlueprintsChangesV0(testState.socket, []string{"test-non-blueprint-changes-v0"})
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "GetBlueprintsChanges failed: %#v", api)
|
||||
require.Greater(t, len(resp.Errors), 0, "failed with no error: %#v", resp)
|
||||
|
|
@ -551,12 +510,12 @@ func TestUndoBlueprintV0(t *testing.T) {
|
|||
}`}
|
||||
|
||||
// Push original version of the blueprint
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bps[0])
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bps[0])
|
||||
require.NoError(t, err, "POST blueprint #0 failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint #0 failed: %#v", resp)
|
||||
|
||||
// Get the commit hash
|
||||
changes, api, err := client.GetBlueprintsChangesV0(testState.socket, []string{"test-undo-blueprint-v0"})
|
||||
changes, api, err := GetBlueprintsChangesV0(testState.socket, []string{"test-undo-blueprint-v0"})
|
||||
require.NoError(t, err, "GET blueprint #0 failed with a client error")
|
||||
require.Nil(t, api, "GetBlueprintsChanges #0 failed: %#v", api)
|
||||
require.Equal(t, 1, len(changes.BlueprintsChanges), "No changes returned")
|
||||
|
|
@ -565,12 +524,12 @@ func TestUndoBlueprintV0(t *testing.T) {
|
|||
require.NotEmpty(t, commit, "First commit is empty")
|
||||
|
||||
// Push the new version with wrong bash version
|
||||
resp, err = client.PostJSONBlueprintV0(testState.socket, bps[1])
|
||||
resp, err = PostJSONBlueprintV0(testState.socket, bps[1])
|
||||
require.NoError(t, err, "POST blueprint #1 failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint #1 failed: %#v", resp)
|
||||
|
||||
// Get the blueprint, confirm bash version is '0.5.*'
|
||||
info, api, err := client.GetBlueprintsInfoJSONV0(testState.socket, "test-undo-blueprint-v0")
|
||||
info, api, err := GetBlueprintsInfoJSONV0(testState.socket, "test-undo-blueprint-v0")
|
||||
require.NoError(t, err, "GET blueprint #1 failed with a client error")
|
||||
require.Nil(t, api, "GetBlueprintsInfo #1 failed: %#v", api)
|
||||
require.Greater(t, len(info.Blueprints), 0, "No blueprints returned")
|
||||
|
|
@ -579,12 +538,12 @@ func TestUndoBlueprintV0(t *testing.T) {
|
|||
require.Equal(t, "0.5.*", info.Blueprints[0].Packages[0].Version, "Wrong version in blueprint")
|
||||
|
||||
// Revert the blueprint to the original version
|
||||
resp, err = client.UndoBlueprintChangeV0(testState.socket, "test-undo-blueprint-v0", commit)
|
||||
resp, err = UndoBlueprintChangeV0(testState.socket, "test-undo-blueprint-v0", commit)
|
||||
require.NoError(t, err, "Undo blueprint failed with a client error")
|
||||
require.True(t, resp.Status, "Undo blueprint failed: %#v", resp)
|
||||
|
||||
// Get the blueprint, confirm bash version is '*'
|
||||
info, api, err = client.GetBlueprintsInfoJSONV0(testState.socket, "test-undo-blueprint-v0")
|
||||
info, api, err = GetBlueprintsInfoJSONV0(testState.socket, "test-undo-blueprint-v0")
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "GetBlueprintsInfo failed: %#v", api)
|
||||
require.Greater(t, len(info.Blueprints), 0, "No blueprints returned")
|
||||
|
|
@ -613,19 +572,19 @@ func TestUndoBlueprintNonCommitV0(t *testing.T) {
|
|||
}`}
|
||||
|
||||
for i := range bps {
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bps[i])
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bps[i])
|
||||
require.NoError(t, err, "POST blueprint #%d failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint #%d failed: %#v", i, resp)
|
||||
}
|
||||
|
||||
resp, err := client.UndoBlueprintChangeV0(testState.socket, "test-undo-blueprint-non-commit-v0", "FFFF")
|
||||
resp, err := UndoBlueprintChangeV0(testState.socket, "test-undo-blueprint-non-commit-v0", "FFFF")
|
||||
require.NoError(t, err, "POST blueprint failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
||||
// Undo non-existent blueprint changes
|
||||
func TestUndoNonBlueprintV0(t *testing.T) {
|
||||
resp, err := client.UndoBlueprintChangeV0(testState.socket, "test-undo-non-blueprint-v0", "FFFF")
|
||||
resp, err := UndoBlueprintChangeV0(testState.socket, "test-undo-non-blueprint-v0", "FFFF")
|
||||
require.NoError(t, err, "blueprint failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
|
@ -652,17 +611,17 @@ func TestBlueprintTagV0(t *testing.T) {
|
|||
}`}
|
||||
|
||||
// Push a blueprint
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bps[0])
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bps[0])
|
||||
require.NoError(t, err, "POST blueprint #0 failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint #0 failed: %#v", resp)
|
||||
|
||||
// Tag the blueprint
|
||||
tagResp, err := client.TagBlueprintV0(testState.socket, "test-tag-blueprint-v0")
|
||||
tagResp, err := TagBlueprintV0(testState.socket, "test-tag-blueprint-v0")
|
||||
require.NoError(t, err, "Tag blueprint #0 failed with a client error")
|
||||
require.True(t, tagResp.Status, "Tag blueprint #0 failed: %#v", resp)
|
||||
|
||||
// Get changes, get the blueprint's revision
|
||||
changes, api, err := client.GetBlueprintsChangesV0(testState.socket, []string{"test-tag-blueprint-v0"})
|
||||
changes, api, err := GetBlueprintsChangesV0(testState.socket, []string{"test-tag-blueprint-v0"})
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "GetBlueprintsChanges failed: %#v", api)
|
||||
require.Equal(t, 1, len(changes.BlueprintsChanges), "No changes returned")
|
||||
|
|
@ -673,17 +632,17 @@ func TestBlueprintTagV0(t *testing.T) {
|
|||
require.NotEqual(t, 0, *revision, "Revision is zero")
|
||||
|
||||
// Push a new version of the blueprint
|
||||
resp, err = client.PostJSONBlueprintV0(testState.socket, bps[1])
|
||||
resp, err = PostJSONBlueprintV0(testState.socket, bps[1])
|
||||
require.NoError(t, err, "POST blueprint #1 failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint #1 failed: %#v", resp)
|
||||
|
||||
// Tag the blueprint
|
||||
tagResp, err = client.TagBlueprintV0(testState.socket, "test-tag-blueprint-v0")
|
||||
tagResp, err = TagBlueprintV0(testState.socket, "test-tag-blueprint-v0")
|
||||
require.NoError(t, err, "Tag blueprint #1 failed with a client error")
|
||||
require.True(t, tagResp.Status, "Tag blueprint #1 failed: %#v", resp)
|
||||
|
||||
// Get changes, confirm that Revision is revision +1
|
||||
changes, api, err = client.GetBlueprintsChangesV0(testState.socket, []string{"test-tag-blueprint-v0"})
|
||||
changes, api, err = GetBlueprintsChangesV0(testState.socket, []string{"test-tag-blueprint-v0"})
|
||||
require.NoError(t, err, "GET blueprint failed with a client error")
|
||||
require.Nil(t, api, "GetBlueprintsChanges failed: %#v", api)
|
||||
require.Equal(t, 1, len(changes.BlueprintsChanges), "No changes returned")
|
||||
|
|
@ -696,7 +655,7 @@ func TestBlueprintTagV0(t *testing.T) {
|
|||
|
||||
// Tag a non-existent blueprint
|
||||
func TestNonBlueprintTagV0(t *testing.T) {
|
||||
tagResp, err := client.TagBlueprintV0(testState.socket, "test-tag-non-blueprint-v0")
|
||||
tagResp, err := TagBlueprintV0(testState.socket, "test-tag-non-blueprint-v0")
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, tagResp.Status, "did not return an error")
|
||||
}
|
||||
|
|
@ -712,12 +671,12 @@ func TestBlueprintDepsolveV0(t *testing.T) {
|
|||
}`
|
||||
|
||||
// Push a blueprint
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bp)
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "POST blueprint failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint failed: %#v", resp)
|
||||
|
||||
// Depsolve the blueprint
|
||||
deps, api, err := client.DepsolveBlueprintV0(testState.socket, "test-deps-blueprint-v0")
|
||||
deps, api, err := DepsolveBlueprintV0(testState.socket, "test-deps-blueprint-v0")
|
||||
require.NoError(t, err, "Depsolve blueprint failed with a client error")
|
||||
require.Nil(t, api, "DepsolveBlueprint failed: %#v", api)
|
||||
require.Greater(t, len(deps.Blueprints), 0, "No blueprint dependencies returned")
|
||||
|
|
@ -730,7 +689,7 @@ func TestBlueprintDepsolveV0(t *testing.T) {
|
|||
|
||||
// depsolve a non-existent blueprint
|
||||
func TestNonBlueprintDepsolveV0(t *testing.T) {
|
||||
resp, api, err := client.DepsolveBlueprintV0(testState.socket, "test-deps-non-blueprint-v0")
|
||||
resp, api, err := DepsolveBlueprintV0(testState.socket, "test-deps-non-blueprint-v0")
|
||||
require.NoError(t, err, "Depsolve blueprint failed with a client error")
|
||||
require.Nil(t, api, "DepsolveBlueprint failed: %#v", api)
|
||||
require.Greater(t, len(resp.Errors), 0, "failed with no error: %#v", resp)
|
||||
|
|
@ -747,12 +706,12 @@ func TestBlueprintFreezeV0(t *testing.T) {
|
|||
}`
|
||||
|
||||
// Push a blueprint
|
||||
resp, err := client.PostJSONBlueprintV0(testState.socket, bp)
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "POST blueprint failed with a client error")
|
||||
require.True(t, resp.Status, "POST blueprint failed: %#v", resp)
|
||||
|
||||
// Freeze the blueprint
|
||||
frozen, api, err := client.FreezeBlueprintV0(testState.socket, "test-freeze-blueprint-v0")
|
||||
frozen, api, err := FreezeBlueprintV0(testState.socket, "test-freeze-blueprint-v0")
|
||||
require.NoError(t, err, "Freeze blueprint failed with a client error")
|
||||
require.Nil(t, api, "FreezeBlueprint failed: %#v", api)
|
||||
require.Greater(t, len(frozen.Blueprints), 0, "No frozen blueprints returned")
|
||||
|
|
@ -766,7 +725,7 @@ func TestBlueprintFreezeV0(t *testing.T) {
|
|||
|
||||
// freeze a non-existent blueprint
|
||||
func TestNonBlueprintFreezeV0(t *testing.T) {
|
||||
resp, api, err := client.FreezeBlueprintV0(testState.socket, "test-freeze-non-blueprint-v0")
|
||||
resp, api, err := FreezeBlueprintV0(testState.socket, "test-freeze-non-blueprint-v0")
|
||||
require.NoError(t, err, "Freeze blueprint failed with a client error")
|
||||
require.Nil(t, api, "FreezeBlueprint failed: %#v", api)
|
||||
require.Greater(t, len(resp.Errors), 0, "failed with no error: %#v", resp)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Package weldrcheck - modules contains functions to check the modules API
|
||||
// Package client - modules_test contains functions to check the modules API
|
||||
// Copyright (C) 2020 by Red Hat, Inc.
|
||||
|
||||
// Tests should be self-contained and not depend on the state of the server
|
||||
|
|
@ -6,23 +6,17 @@
|
|||
// They should not assume version numbers for packages will match
|
||||
// They should run tests that depend on previous results from the same function
|
||||
// not from other functions.
|
||||
|
||||
// +build integration
|
||||
|
||||
package weldrcheck
|
||||
package client
|
||||
|
||||
import (
|
||||
// "strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/client"
|
||||
)
|
||||
|
||||
// List all the modules
|
||||
func TestListAllModulesV0(t *testing.T) {
|
||||
modules, api, err := client.ListAllModulesV0(testState.socket)
|
||||
modules, api, err := ListAllModulesV0(testState.socket)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, api, "ListAllModules failed: %#v", api)
|
||||
require.True(t, len(modules) > 1, "Not enough modules returned")
|
||||
|
|
@ -30,7 +24,7 @@ func TestListAllModulesV0(t *testing.T) {
|
|||
|
||||
// List some modules
|
||||
func TestListSomeModulesV0(t *testing.T) {
|
||||
modules, api, err := client.ListSomeModulesV0(testState.socket, 0, 5)
|
||||
modules, api, err := ListSomeModulesV0(testState.socket, 0, 5)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, api, "ListSomeProjects failed: %#v", api)
|
||||
require.True(t, len(modules) == 5, "Not enough modules returned")
|
||||
|
|
@ -38,7 +32,7 @@ func TestListSomeModulesV0(t *testing.T) {
|
|||
|
||||
// List one module
|
||||
func TestListOneModulesV0(t *testing.T) {
|
||||
modules, api, err := client.ListModulesV0(testState.socket, "bash")
|
||||
modules, api, err := ListModulesV0(testState.socket, "bash")
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, api, "ListModules failed: %#v", api)
|
||||
require.True(t, len(modules) == 1, "Not enough modules returned")
|
||||
|
|
@ -46,7 +40,7 @@ func TestListOneModulesV0(t *testing.T) {
|
|||
|
||||
// List two modules
|
||||
func TestListTwoModulesV0(t *testing.T) {
|
||||
modules, api, err := client.ListModulesV0(testState.socket, "bash,tmux")
|
||||
modules, api, err := ListModulesV0(testState.socket, "bash,tmux")
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, api, "ListModules failed: %#v", api)
|
||||
require.True(t, len(modules) == 2, "Not enough modules returned")
|
||||
|
|
@ -54,7 +48,7 @@ func TestListTwoModulesV0(t *testing.T) {
|
|||
|
||||
// Get info on a specific module
|
||||
func TestOneModuleInfoV0(t *testing.T) {
|
||||
modules, api, err := client.GetModulesInfoV0(testState.socket, "bash")
|
||||
modules, api, err := GetModulesInfoV0(testState.socket, "bash")
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, api, "GetModulesInfo failed: %#v", api)
|
||||
require.True(t, len(modules) == 1, "Not enough modules returned: %#v", modules)
|
||||
|
|
@ -62,7 +56,7 @@ func TestOneModuleInfoV0(t *testing.T) {
|
|||
|
||||
// Get info on two specific modules
|
||||
func TestTwoModuleInfoV0(t *testing.T) {
|
||||
modules, api, err := client.GetModulesInfoV0(testState.socket, "bash,tmux")
|
||||
modules, api, err := GetModulesInfoV0(testState.socket, "bash,tmux")
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, api, "GetModulesInfo failed: %#v", api)
|
||||
require.True(t, len(modules) == 2, "Not enough modules returned: %#v", modules)
|
||||
|
|
@ -70,7 +64,7 @@ func TestTwoModuleInfoV0(t *testing.T) {
|
|||
|
||||
// Test an invalid info request
|
||||
func TestEmptyModuleInfoV0(t *testing.T) {
|
||||
modules, api, err := client.GetModulesInfoV0(testState.socket, "")
|
||||
modules, api, err := GetModulesInfoV0(testState.socket, "")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, api, "did not return an error")
|
||||
require.False(t, api.Status, "wrong Status (true)")
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Package weldrcheck - projects contains functions to check the projects API
|
||||
// Package client - projects_test contains functions to check the projects API
|
||||
// Copyright (C) 2020 by Red Hat, Inc.
|
||||
|
||||
// Tests should be self-contained and not depend on the state of the server
|
||||
|
|
@ -6,23 +6,18 @@
|
|||
// They should not assume version numbers for packages will match
|
||||
// They should run tests that depend on previous results from the same function
|
||||
// not from other functions.
|
||||
|
||||
// +build integration
|
||||
|
||||
package weldrcheck
|
||||
package client
|
||||
|
||||
import (
|
||||
// "strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/client"
|
||||
)
|
||||
|
||||
// List all the projects
|
||||
func TestListAllProjectsV0(t *testing.T) {
|
||||
projs, api, err := client.ListAllProjectsV0(testState.socket)
|
||||
projs, api, err := ListAllProjectsV0(testState.socket)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, api, "ListAllProjects failed: %#v", api)
|
||||
require.True(t, len(projs) > 1, "Not enough projects returned")
|
||||
|
|
@ -30,7 +25,7 @@ func TestListAllProjectsV0(t *testing.T) {
|
|||
|
||||
// List some of the projects
|
||||
func TestListSomeProjectsV0(t *testing.T) {
|
||||
projs, api, err := client.ListSomeProjectsV0(testState.socket, 0, 5)
|
||||
projs, api, err := ListSomeProjectsV0(testState.socket, 0, 5)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, api, "ListSomeProjects failed: %#v", api)
|
||||
require.True(t, len(projs) == 5, "Not enough projects returned")
|
||||
|
|
@ -38,7 +33,7 @@ func TestListSomeProjectsV0(t *testing.T) {
|
|||
|
||||
// Get info on a specific project
|
||||
func TestOneProjectsInfoV0(t *testing.T) {
|
||||
projs, api, err := client.GetProjectsInfoV0(testState.socket, "bash")
|
||||
projs, api, err := GetProjectsInfoV0(testState.socket, "bash")
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, api, "GetProjectsInfo failed: %#v", api)
|
||||
require.True(t, len(projs) == 1, "Not enough projects returned")
|
||||
|
|
@ -46,7 +41,7 @@ func TestOneProjectsInfoV0(t *testing.T) {
|
|||
|
||||
// Get info on a two specific projects
|
||||
func TestTwoProjectsInfoV0(t *testing.T) {
|
||||
projs, api, err := client.GetProjectsInfoV0(testState.socket, "bash,tmux")
|
||||
projs, api, err := GetProjectsInfoV0(testState.socket, "bash,tmux")
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, api, "GetProjectsInfo failed: %#v", api)
|
||||
require.True(t, len(projs) == 2, "Not enough projects returned")
|
||||
|
|
@ -54,7 +49,7 @@ func TestTwoProjectsInfoV0(t *testing.T) {
|
|||
|
||||
// Test an invalid info request
|
||||
func TestEmptyProjectsInfoV0(t *testing.T) {
|
||||
projs, api, err := client.GetProjectsInfoV0(testState.socket, "")
|
||||
projs, api, err := GetProjectsInfoV0(testState.socket, "")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, api, "did not return an error")
|
||||
require.False(t, api.Status, "wrong Status (true)")
|
||||
|
|
@ -63,7 +58,7 @@ func TestEmptyProjectsInfoV0(t *testing.T) {
|
|||
|
||||
// Depsolve projects
|
||||
func TestDepsolveOneProjectV0(t *testing.T) {
|
||||
deps, api, err := client.DepsolveProjectsV0(testState.socket, "bash")
|
||||
deps, api, err := DepsolveProjectsV0(testState.socket, "bash")
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, api, "DepsolveProjects failed: %#v", api)
|
||||
require.True(t, len(deps) > 2, "Not enough dependencies returned")
|
||||
|
|
@ -71,7 +66,7 @@ func TestDepsolveOneProjectV0(t *testing.T) {
|
|||
|
||||
// Depsolve several projects
|
||||
func TestDepsolveTwoProjectV0(t *testing.T) {
|
||||
deps, api, err := client.DepsolveProjectsV0(testState.socket, "bash,tmux")
|
||||
deps, api, err := DepsolveProjectsV0(testState.socket, "bash,tmux")
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, api, "DepsolveProjects failed: %#v", api)
|
||||
require.True(t, len(deps) > 2, "Not enough dependencies returned")
|
||||
|
|
@ -79,7 +74,7 @@ func TestDepsolveTwoProjectV0(t *testing.T) {
|
|||
|
||||
// Depsolve empty projects list
|
||||
func TestEmptyDepsolveProjectV0(t *testing.T) {
|
||||
deps, api, err := client.DepsolveProjectsV0(testState.socket, "")
|
||||
deps, api, err := DepsolveProjectsV0(testState.socket, "")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, api, "did not return an error")
|
||||
require.False(t, api.Status, "wrong Status (true)")
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Package weldrcheck - source contains functions to check the source API
|
||||
// Package client - source_test contains functions to check the source API
|
||||
// Copyright (C) 2020 by Red Hat, Inc.
|
||||
|
||||
// Tests should be self-contained and not depend on the state of the server
|
||||
|
|
@ -6,18 +6,13 @@
|
|||
// They should not assume version numbers for packages will match
|
||||
// They should run tests that depend on previous results from the same function
|
||||
// not from other functions.
|
||||
|
||||
// +build integration
|
||||
|
||||
package weldrcheck
|
||||
package client
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/client"
|
||||
)
|
||||
|
||||
// POST a new JSON source
|
||||
|
|
@ -33,18 +28,18 @@ func TestPOSTJSONSourceV0(t *testing.T) {
|
|||
}`
|
||||
source = strings.Replace(source, "REPO-PATH", testState.repoDir, 1)
|
||||
|
||||
resp, err := client.PostJSONSourceV0(testState.socket, source)
|
||||
resp, err := PostJSONSourceV0(testState.socket, source)
|
||||
require.NoError(t, err, "POST source failed with a client error")
|
||||
require.True(t, resp.Status, "POST source failed: %#v", resp)
|
||||
|
||||
resp, err = client.DeleteSourceV0(testState.socket, "package-repo-json-v0")
|
||||
resp, err = DeleteSourceV0(testState.socket, "package-repo-json-v0")
|
||||
require.NoError(t, err, "DELETE source failed with a client error")
|
||||
require.True(t, resp.Status, "DELETE source failed: %#v", resp)
|
||||
}
|
||||
|
||||
// POST an empty JSON source
|
||||
func TestPOSTEmptyJSONSourceV0(t *testing.T) {
|
||||
resp, err := client.PostJSONSourceV0(testState.socket, "")
|
||||
resp, err := PostJSONSourceV0(testState.socket, "")
|
||||
require.NoError(t, err, "POST source failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
|
@ -62,7 +57,7 @@ func TestPOSTInvalidJSONSourceV0(t *testing.T) {
|
|||
"gpgkey_urls": ["https://url/path/to/gpg-key"]
|
||||
}`
|
||||
|
||||
resp, err := client.PostJSONSourceV0(testState.socket, source)
|
||||
resp, err := PostJSONSourceV0(testState.socket, source)
|
||||
require.NoError(t, err, "POST source failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
|
@ -80,18 +75,18 @@ func TestPOSTTOMLSourceV0(t *testing.T) {
|
|||
`
|
||||
source = strings.Replace(source, "REPO-PATH", testState.repoDir, 1)
|
||||
|
||||
resp, err := client.PostTOMLSourceV0(testState.socket, source)
|
||||
resp, err := PostTOMLSourceV0(testState.socket, source)
|
||||
require.NoError(t, err, "POST source failed with a client error")
|
||||
require.True(t, resp.Status, "POST source failed: %#v", resp)
|
||||
|
||||
resp, err = client.DeleteSourceV0(testState.socket, "package-repo-toml-v0")
|
||||
resp, err = DeleteSourceV0(testState.socket, "package-repo-toml-v0")
|
||||
require.NoError(t, err, "DELETE source failed with a client error")
|
||||
require.True(t, resp.Status, "DELETE source failed: %#v", resp)
|
||||
}
|
||||
|
||||
// POST an empty TOML source
|
||||
func TestPOSTEmptyTOMLSourceV0(t *testing.T) {
|
||||
resp, err := client.PostTOMLSourceV0(testState.socket, "")
|
||||
resp, err := PostTOMLSourceV0(testState.socket, "")
|
||||
require.NoError(t, err, "POST source failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
|
@ -109,7 +104,7 @@ func TestPOSTInvalidTOMLSourceV0(t *testing.T) {
|
|||
gpgkey_urls = ["https://url/path/to/gpg-key"]
|
||||
`
|
||||
|
||||
resp, err := client.PostTOMLSourceV0(testState.socket, source)
|
||||
resp, err := PostTOMLSourceV0(testState.socket, source)
|
||||
require.NoError(t, err, "POST source failed with a client error")
|
||||
require.False(t, resp.Status, "did not return an error")
|
||||
}
|
||||
|
|
@ -137,7 +132,7 @@ func TestListSourcesV0(t *testing.T) {
|
|||
|
||||
for i := range sources {
|
||||
source := strings.Replace(sources[i], "REPO-PATH", testState.repoDir, 1)
|
||||
resp, err := client.PostJSONSourceV0(testState.socket, source)
|
||||
resp, err := PostJSONSourceV0(testState.socket, source)
|
||||
require.NoError(t, err, "POST source failed with a client error")
|
||||
require.True(t, resp.Status, "POST source failed: %#v", resp)
|
||||
}
|
||||
|
|
@ -145,14 +140,14 @@ func TestListSourcesV0(t *testing.T) {
|
|||
// Remove the test sources, ignoring any errors
|
||||
defer func() {
|
||||
for _, n := range []string{"package-repo-1", "package-repo-2"} {
|
||||
resp, err := client.DeleteSourceV0(testState.socket, n)
|
||||
resp, err := DeleteSourceV0(testState.socket, n)
|
||||
require.NoError(t, err, "DELETE source failed with a client error")
|
||||
require.True(t, resp.Status, "DELETE source failed: %#v", resp)
|
||||
}
|
||||
}()
|
||||
|
||||
// Get the list of sources
|
||||
list, api, err := client.ListSourcesV0(testState.socket)
|
||||
list, api, err := ListSourcesV0(testState.socket)
|
||||
require.NoError(t, err, "GET source failed with a client error")
|
||||
require.Nil(t, api, "ListSources failed: %#v", api)
|
||||
require.True(t, len(list) > 1, "Not enough sources returned")
|
||||
|
|
@ -173,18 +168,18 @@ func TestGetSourceInfoV0(t *testing.T) {
|
|||
`
|
||||
source = strings.Replace(source, "REPO-PATH", testState.repoDir, 1)
|
||||
|
||||
resp, err := client.PostTOMLSourceV0(testState.socket, source)
|
||||
resp, err := PostTOMLSourceV0(testState.socket, source)
|
||||
require.NoError(t, err, "POST source failed with a client error")
|
||||
require.True(t, resp.Status, "POST source failed: %#v", resp)
|
||||
|
||||
info, resp, err := client.GetSourceInfoV0(testState.socket, "package-repo-info-v0")
|
||||
info, resp, err := GetSourceInfoV0(testState.socket, "package-repo-info-v0")
|
||||
require.NoError(t, err, "GET source failed with a client error")
|
||||
require.Nil(t, resp, "GET source failed: %#v", resp)
|
||||
require.Contains(t, info, "package-repo-info-v0", "No source info returned")
|
||||
require.Equal(t, "package-repo-info-v0", info["package-repo-info-v0"].Name)
|
||||
require.Equal(t, "file://"+testState.repoDir, info["package-repo-info-v0"].URL)
|
||||
|
||||
resp, err = client.DeleteSourceV0(testState.socket, "package-repo-info-v0")
|
||||
resp, err = DeleteSourceV0(testState.socket, "package-repo-info-v0")
|
||||
require.NoError(t, err, "DELETE source failed with a client error")
|
||||
require.True(t, resp.Status, "DELETE source failed: %#v", resp)
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Package weldrcheck contains functions used to run integration tests on a running API server
|
||||
// Copyright (C) 2020 by Red Hat, Inc.
|
||||
|
||||
// nolint: deadcode // These functions are used by the *_test.go code
|
||||
// nolint: deadcode,unused // These functions are used by the *_test.go code
|
||||
package client
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,67 +0,0 @@
|
|||
// Package weldrcheck contains functions used to run integration tests on a running API server
|
||||
// Copyright (C) 2020 by Red Hat, Inc.
|
||||
|
||||
// +build integration
|
||||
|
||||
// nolint: deadcode // These functions are used by the *_test.go code
|
||||
package weldrcheck
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/client"
|
||||
)
|
||||
|
||||
type TestState struct {
|
||||
socket *http.Client
|
||||
apiVersion int
|
||||
repoDir string
|
||||
}
|
||||
|
||||
// isStringInSlice returns true if the string is present, false if not
|
||||
// slice must be sorted
|
||||
// TODO decide if this belongs in a more widely useful package location
|
||||
func isStringInSlice(slice []string, s string) bool {
|
||||
i := sort.SearchStrings(slice, s)
|
||||
if i < len(slice) && slice[i] == s {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func setUpTestState(socketPath string, timeout time.Duration) (*TestState, error) {
|
||||
var state TestState
|
||||
state.socket = &http.Client{
|
||||
// TODO This may be too short/simple for downloading images
|
||||
Timeout: timeout,
|
||||
Transport: &http.Transport{
|
||||
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
|
||||
return net.Dial("unix", socketPath)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Make sure the server is running
|
||||
status, resp, err := client.GetStatusV0(state.socket)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("status request failed with client error: %s", err)
|
||||
}
|
||||
if resp != nil {
|
||||
return nil, fmt.Errorf("status request failed: %v\n", resp)
|
||||
}
|
||||
apiVersion, e := strconv.Atoi(status.API)
|
||||
if e != nil {
|
||||
state.apiVersion = 0
|
||||
} else {
|
||||
state.apiVersion = apiVersion
|
||||
}
|
||||
fmt.Printf("Running tests against %s %s server using V%d API\n\n", status.Backend, status.Build, state.apiVersion)
|
||||
|
||||
return &state, nil
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ TEST_LDFLAGS="${LDFLAGS:-} -B 0x$(od -N 20 -An -tx1 -w100 /dev/urandom | tr -d '
|
|||
|
||||
go test -c -tags=integration -ldflags="${TEST_LDFLAGS}" -o _bin/osbuild-tests %{goipath}/cmd/osbuild-tests
|
||||
go test -c -tags=integration -ldflags="${TEST_LDFLAGS}" -o _bin/osbuild-dnf-json-tests %{goipath}/cmd/osbuild-dnf-json-tests
|
||||
go test -c -tags=integration -ldflags="${TEST_LDFLAGS}" -o _bin/osbuild-weldr-tests %{goipath}/internal/weldrcheck/
|
||||
go test -c -tags=integration -ldflags="${TEST_LDFLAGS}" -o _bin/osbuild-weldr-tests %{goipath}/internal/client/
|
||||
go test -c -tags=integration -ldflags="${TEST_LDFLAGS}" -o _bin/osbuild-rcm-tests %{goipath}/cmd/osbuild-rcm-tests
|
||||
go test -c -tags=integration -ldflags="${TEST_LDFLAGS}" -o _bin/osbuild-image-tests %{goipath}/cmd/osbuild-image-tests
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue