From dec257bf83b2fbe86156b7b364e71f4efdc24bf9 Mon Sep 17 00:00:00 2001 From: Katy Moe Date: Fri, 24 Jun 2022 17:34:43 +0100 Subject: [PATCH] add basic e2e tests for state push/pull --- tfexec/internal/e2etest/state_pull_test.go | 28 ++++++++++++++++++++++ tfexec/internal/e2etest/state_push_test.go | 28 ++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tfexec/internal/e2etest/state_pull_test.go create mode 100644 tfexec/internal/e2etest/state_push_test.go diff --git a/tfexec/internal/e2etest/state_pull_test.go b/tfexec/internal/e2etest/state_pull_test.go new file mode 100644 index 00000000..032173fb --- /dev/null +++ b/tfexec/internal/e2etest/state_pull_test.go @@ -0,0 +1,28 @@ +package e2etest + +import ( + "context" + "testing" + + "github.com/hashicorp/go-version" + + "github.com/hashicorp/terraform-exec/tfexec" +) + +func TestStatePull(t *testing.T) { + runTest(t, "basic_with_state", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) { + if tfv.LessThan(providerAddressMinVersion) { + t.Skip("state file provider FQNs not compatible with this Terraform version") + } + + err := tf.Init(context.Background()) + if err != nil { + t.Fatalf("error running Init in test directory: %s", err) + } + + _, err = tf.StatePull(context.Background()) + if err != nil { + t.Fatalf("error running StatePull: %s", err) + } + }) +} diff --git a/tfexec/internal/e2etest/state_push_test.go b/tfexec/internal/e2etest/state_push_test.go new file mode 100644 index 00000000..749b409a --- /dev/null +++ b/tfexec/internal/e2etest/state_push_test.go @@ -0,0 +1,28 @@ +package e2etest + +import ( + "context" + "testing" + + "github.com/hashicorp/go-version" + + "github.com/hashicorp/terraform-exec/tfexec" +) + +func TestStatePush(t *testing.T) { + runTest(t, "basic_with_state", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) { + if tfv.LessThan(providerAddressMinVersion) { + t.Skip("state file provider FQNs not compatible with this Terraform version") + } + + err := tf.Init(context.Background()) + if err != nil { + t.Fatalf("error running Init in test directory: %s", err) + } + + err = tf.StatePush(context.Background(), "terraform.tfstate") + if err != nil { + t.Fatalf("error running StatePush: %s", err) + } + }) +}