mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 16:31:10 -06:00
b802db75d7
This uses the decoupled build and run strategy to run the e2etests so that we can arrange to run the tests against the real release packages produced elsewhere in this workflow, rather than ones generated just in time by the test harness. The modifications to make-archive.sh here make it more consistent with its originally-intended purpose of producing a harness for testing "real" release executables. Our earlier compromise of making it include its own terraform executable came from a desire to use that script as part of manual cross-platform testing when we weren't yet set up to support automation of those tests as we're doing here. That does mean, however, that the terraform-e2etest package content must be combined with content from a terraform release package in order to produce a valid contest for running the tests. We use a single job to cross-compile the test harness for all of the supported platforms, because that build is relatively fast and so not worth the overhead of matrix build, but then use a matrix build to actually run the tests so that we can run them in a worker matching the target platform. We currently have access only to amd64 (x64) runners in GitHub Actions and so for the moment this process is limited only to the subset of our supported platforms which use that architecture.
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
package e2etest
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/internal/e2e"
|
|
)
|
|
|
|
var terraformBin string
|
|
|
|
// canRunGoBuild is a short-term compromise to account for the fact that we
|
|
// have a small number of tests that work by building helper programs using
|
|
// "go build" at runtime, but we can't do that in our isolated test mode
|
|
// driven by the make-archive.sh script.
|
|
//
|
|
// FIXME: Rework this a bit so that we build the necessary helper programs
|
|
// (test plugins, etc) as part of the initial suite setup, and in the
|
|
// make-archive.sh script, so that we can run all of the tests in both
|
|
// situations with the tests just using the executable already built for
|
|
// them, as we do for terraformBin.
|
|
var canRunGoBuild bool
|
|
|
|
func TestMain(m *testing.M) {
|
|
teardown := setup()
|
|
code := m.Run()
|
|
teardown()
|
|
os.Exit(code)
|
|
}
|
|
|
|
func setup() func() {
|
|
if terraformBin != "" {
|
|
// this is pre-set when we're running in a binary produced from
|
|
// the make-archive.sh script, since that is for testing an
|
|
// executable obtained from a real release package. However, we do
|
|
// need to turn it into an absolute path so that we can find it
|
|
// when we change the working directory during tests.
|
|
var err error
|
|
terraformBin, err = filepath.Abs(terraformBin)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("failed to find absolute path of terraform executable: %s", err))
|
|
}
|
|
return func() {}
|
|
}
|
|
|
|
tmpFilename := e2e.GoBuild("github.com/hashicorp/terraform", "terraform")
|
|
|
|
// Make the executable available for use in tests
|
|
terraformBin = tmpFilename
|
|
|
|
// Tests running in the ad-hoc testing mode are allowed to use "go build"
|
|
// and similar to produce other test executables.
|
|
// (See the comment on this variable's declaration for more information.)
|
|
canRunGoBuild = true
|
|
|
|
return func() {
|
|
os.Remove(tmpFilename)
|
|
}
|
|
}
|
|
|
|
func canAccessNetwork() bool {
|
|
// We re-use the flag normally used for acceptance tests since that's
|
|
// established as a way to opt-in to reaching out to real systems that
|
|
// may suffer transient errors.
|
|
return os.Getenv("TF_ACC") != ""
|
|
}
|
|
|
|
func skipIfCannotAccessNetwork(t *testing.T) {
|
|
t.Helper()
|
|
|
|
if !canAccessNetwork() {
|
|
t.Skip("network access not allowed; use TF_ACC=1 to enable")
|
|
}
|
|
}
|