debian-forge-composer/internal/client/integration_test.go
Brian C. Lane e3934108f7 client: Handle the differences between unit tests and integration tests
The mock server used by unit tests is slightly different than the
running server, mostly related to package names that are hard-coded.

This adds a bool to testState that can be used in the tests to alter the
expected behavior. It should be used as little as possible.
2020-03-27 19:07:33 +01:00

47 lines
1 KiB
Go

// Package client - integration_test contains functions to setup integration tests
// Copyright (C) 2020 by Red Hat, Inc.
// +build integration
package client
import (
"fmt"
"os"
"testing"
"time"
"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, false)
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)
}