mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
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.
79 lines
2.7 KiB
Go
79 lines
2.7 KiB
Go
package e2etest
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/internal/e2e"
|
|
"github.com/hashicorp/terraform/internal/getproviders"
|
|
)
|
|
|
|
// TestProviderProtocols verifies that Terraform can execute provider plugins
|
|
// with both supported protocol versions.
|
|
func TestProviderProtocols(t *testing.T) {
|
|
if !canRunGoBuild {
|
|
// We're running in a separate-build-then-run context, so we can't
|
|
// currently execute this test which depends on being able to build
|
|
// new executable at runtime.
|
|
//
|
|
// (See the comment on canRunGoBuild's declaration for more information.)
|
|
t.Skip("can't run without building a new provider executable")
|
|
}
|
|
t.Parallel()
|
|
|
|
tf := e2e.NewBinary(terraformBin, "testdata/provider-plugin")
|
|
defer tf.Close()
|
|
|
|
// In order to do a decent end-to-end test for this case we will need a real
|
|
// enough provider plugin to try to run and make sure we are able to
|
|
// actually run it. Here will build the simple and simple6 (built with
|
|
// protocol v6) providers.
|
|
simple6Provider := filepath.Join(tf.WorkDir(), "terraform-provider-simple6")
|
|
simple6ProviderExe := e2e.GoBuild("github.com/hashicorp/terraform/internal/provider-simple-v6/main", simple6Provider)
|
|
|
|
simpleProvider := filepath.Join(tf.WorkDir(), "terraform-provider-simple")
|
|
simpleProviderExe := e2e.GoBuild("github.com/hashicorp/terraform/internal/provider-simple/main", simpleProvider)
|
|
|
|
// Move the provider binaries into a directory that we will point terraform
|
|
// to using the -plugin-dir cli flag.
|
|
platform := getproviders.CurrentPlatform.String()
|
|
hashiDir := "cache/registry.terraform.io/hashicorp/"
|
|
if err := os.MkdirAll(tf.Path(hashiDir, "simple6/0.0.1/", platform), os.ModePerm); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Rename(simple6ProviderExe, tf.Path(hashiDir, "simple6/0.0.1/", platform, "terraform-provider-simple6")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := os.MkdirAll(tf.Path(hashiDir, "simple/0.0.1/", platform), os.ModePerm); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Rename(simpleProviderExe, tf.Path(hashiDir, "simple/0.0.1/", platform, "terraform-provider-simple")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
//// INIT
|
|
_, stderr, err := tf.Run("init", "-plugin-dir=cache")
|
|
if err != nil {
|
|
t.Fatalf("unexpected init error: %s\nstderr:\n%s", err, stderr)
|
|
}
|
|
|
|
//// PLAN
|
|
_, stderr, err = tf.Run("plan", "-out=tfplan")
|
|
if err != nil {
|
|
t.Fatalf("unexpected plan error: %s\nstderr:\n%s", err, stderr)
|
|
}
|
|
|
|
//// APPLY
|
|
stdout, stderr, err := tf.Run("apply", "tfplan")
|
|
if err != nil {
|
|
t.Fatalf("unexpected apply error: %s\nstderr:\n%s", err, stderr)
|
|
}
|
|
|
|
if !strings.Contains(stdout, "Apply complete! Resources: 2 added, 0 changed, 0 destroyed.") {
|
|
t.Fatalf("wrong output:\n%s", stdout)
|
|
}
|
|
}
|