2017-07-08 03:47:56 +02:00
|
|
|
package e2etest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-08-16 15:48:51 +02:00
|
|
|
"path/filepath"
|
2017-07-08 03:47:56 +02:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2017-08-16 15:48:51 +02:00
|
|
|
"github.com/hashicorp/terraform/e2e"
|
2020-11-24 22:50:18 +01:00
|
|
|
"github.com/hashicorp/terraform/version"
|
2017-07-08 03:47:56 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVersion(t *testing.T) {
|
|
|
|
// Along with testing the "version" command in particular, this serves
|
|
|
|
// as a good smoke test for whether the Terraform binary can even be
|
|
|
|
// compiled and run, since it doesn't require any external network access
|
|
|
|
// to do its job.
|
|
|
|
|
|
|
|
t.Parallel()
|
|
|
|
|
2019-06-30 09:38:36 +02:00
|
|
|
fixturePath := filepath.Join("testdata", "empty")
|
2017-08-16 15:48:51 +02:00
|
|
|
tf := e2e.NewBinary(terraformBin, fixturePath)
|
2017-07-08 03:47:56 +02:00
|
|
|
defer tf.Close()
|
|
|
|
|
|
|
|
stdout, stderr, err := tf.Run("version")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if stderr != "" {
|
|
|
|
t.Errorf("unexpected stderr output:\n%s", stderr)
|
|
|
|
}
|
|
|
|
|
2020-11-24 22:50:18 +01:00
|
|
|
wantVersion := fmt.Sprintf("Terraform v%s", version.String())
|
2017-10-24 21:25:22 +02:00
|
|
|
if !strings.Contains(stdout, wantVersion) {
|
2017-07-08 03:47:56 +02:00
|
|
|
t.Errorf("output does not contain our current version %q:\n%s", wantVersion, stdout)
|
|
|
|
}
|
|
|
|
}
|
2017-10-24 21:27:38 +02:00
|
|
|
|
|
|
|
func TestVersionWithProvider(t *testing.T) {
|
|
|
|
// This is a more elaborate use of "version" that shows the selected
|
|
|
|
// versions of plugins too.
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
// This test reaches out to releases.hashicorp.com to download the
|
|
|
|
// template and null providers, so it can only run if network access is
|
|
|
|
// allowed.
|
|
|
|
skipIfCannotAccessNetwork(t)
|
|
|
|
|
2019-06-30 09:38:36 +02:00
|
|
|
fixturePath := filepath.Join("testdata", "template-provider")
|
2017-10-24 21:27:38 +02:00
|
|
|
tf := e2e.NewBinary(terraformBin, fixturePath)
|
|
|
|
defer tf.Close()
|
|
|
|
|
|
|
|
// Initial run (before "init") should work without error but will not
|
|
|
|
// include the provider version, since we've not "locked" one yet.
|
|
|
|
{
|
|
|
|
stdout, stderr, err := tf.Run("version")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if stderr != "" {
|
|
|
|
t.Errorf("unexpected stderr output:\n%s", stderr)
|
|
|
|
}
|
|
|
|
|
2020-11-24 22:50:18 +01:00
|
|
|
wantVersion := fmt.Sprintf("Terraform v%s", version.String())
|
2017-10-24 21:27:38 +02:00
|
|
|
if !strings.Contains(stdout, wantVersion) {
|
|
|
|
t.Errorf("output does not contain our current version %q:\n%s", wantVersion, stdout)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
_, _, err := tf.Run("init")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// After running init, we additionally include information about the
|
|
|
|
// selected version of the "template" provider.
|
|
|
|
{
|
|
|
|
stdout, stderr, err := tf.Run("version")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if stderr != "" {
|
|
|
|
t.Errorf("unexpected stderr output:\n%s", stderr)
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:41:20 +02:00
|
|
|
wantMsg := "+ provider registry.terraform.io/hashicorp/template v" // we don't know which version we'll get here
|
2017-10-24 21:27:38 +02:00
|
|
|
if !strings.Contains(stdout, wantMsg) {
|
|
|
|
t.Errorf("output does not contain provider information %q:\n%s", wantMsg, stdout)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|