From 52df81ee497e06b8db1b8ec7b762ce4af544c3b3 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 7 Jul 2017 18:49:41 -0700 Subject: [PATCH] command/e2etest: test that we can install provider plugins We already have good tests for the business logic around provider installation, but the existing tests all stub out the main repository server. This test completes that coverage by verifying that the installer is able to run against the real repository and install an official release of the template provider. --- command/e2etest/init_test.go | 43 +++++++++++++++++++ .../test-fixtures/template-provider/main.tf | 7 +++ 2 files changed, 50 insertions(+) create mode 100644 command/e2etest/init_test.go create mode 100644 command/e2etest/test-fixtures/template-provider/main.tf diff --git a/command/e2etest/init_test.go b/command/e2etest/init_test.go new file mode 100644 index 0000000000..7a5ec2ab23 --- /dev/null +++ b/command/e2etest/init_test.go @@ -0,0 +1,43 @@ +package e2etest + +import ( + "strings" + "testing" +) + +func TestInitProviders(t *testing.T) { + t.Parallel() + + // This test reaches out to releases.hashicorp.com to download the + // template provider, so it can only run if network access is allowed. + // We intentionally don't try to stub this here, because there's already + // a stubbed version of this in the "command" package and so the goal here + // is to test the interaction with the real repository. + skipIfCannotAccessNetwork(t) + + tf := newTerraform("template-provider") + defer tf.Close() + + stdout, stderr, err := tf.Run("init") + if err != nil { + t.Errorf("unexpected error: %s", err) + } + + if stderr != "" { + t.Errorf("unexpected stderr output:\n%s", stderr) + } + + if !strings.Contains(stdout, "Terraform has been successfully initialized!") { + t.Errorf("success message is missing from output:\n%s", stdout) + } + + if !strings.Contains(stdout, "- Downloading plugin for provider \"template\"") { + t.Errorf("provider download message is missing from output:\n%s", stdout) + t.Logf("(this can happen if you have a copy of the plugin in one of the global plugin search dirs)") + } + + if !strings.Contains(stdout, "* provider.template: version = ") { + t.Errorf("provider pinning recommendation is missing from output:\n%s", stdout) + } + +} diff --git a/command/e2etest/test-fixtures/template-provider/main.tf b/command/e2etest/test-fixtures/template-provider/main.tf new file mode 100644 index 0000000000..31af45150a --- /dev/null +++ b/command/e2etest/test-fixtures/template-provider/main.tf @@ -0,0 +1,7 @@ +provider "template" { + +} + +data "template_file" "test" { + template = "Hello World" +}