opentofu/command/e2etest/main_test.go
Martin Atkins eed605ac05 [WIP] Re-enable the end-to-end tests (#20044)
* internal/initwd: Allow deprecated relative module paths

In Terraform 0.11 we deprecated this form but didn't have any explicit
warning for it. Now we'll still accept it but generate a warning. In a
future major release we will drop this form altogether, since it is
ambiguous with registry module source addresses.

This codepath is covered by the command/e2etest suite.

* e2e: Skip copying .exists file, if present

We use this only in the "empty" test fixture in order to let git know that
the directory exists. We need to skip copying it so that we can test
"terraform init -from-module=...", which expects to find an empty
directory.

* command/e2etests: Re-enable and fix up the e2etest "acctests"

We disabled all of the tests that accessed remote services like the
Terraform Registry while they were being updated to support the new
protocols we now expect. With those services now in place, we can
re-enable these tests.

Some details of exactly what output we print, etc, have intentionally
changed since these tests were last updated.

* e2e: refactor for modern states and plans

* command/e2etest: re-enable e2etests and update for tf 0.12 compatibility
plugin/discovery: mkdirAll instead of mkdir when creating cache dir
2019-04-29 13:03:24 -04:00

60 lines
1.3 KiB
Go

package e2etest
import (
"fmt"
"os"
"path/filepath"
"testing"
"github.com/hashicorp/terraform/e2e"
)
var terraformBin string
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 builds a ready-to-go
// binary into the archive. 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
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")
}
}