From 816a09fd9d9ca161798ec247b7723617cf1cd4a9 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Wed, 25 Mar 2020 16:59:09 -0700 Subject: [PATCH] client: Add integration test setup code --- internal/client/integration_test.go | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 internal/client/integration_test.go diff --git a/internal/client/integration_test.go b/internal/client/integration_test.go new file mode 100644 index 000000000..7f6bee16f --- /dev/null +++ b/internal/client/integration_test.go @@ -0,0 +1,47 @@ +// 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) + 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) +}