github.com/hooklift/terraform@v0.11.0-beta1.0.20171117000744-6786c1361ffe/command/e2etest/version_test.go (about) 1 package e2etest 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "strings" 7 "testing" 8 9 "github.com/hashicorp/terraform/e2e" 10 tfcore "github.com/hashicorp/terraform/terraform" 11 ) 12 13 func TestVersion(t *testing.T) { 14 // Along with testing the "version" command in particular, this serves 15 // as a good smoke test for whether the Terraform binary can even be 16 // compiled and run, since it doesn't require any external network access 17 // to do its job. 18 19 t.Parallel() 20 21 fixturePath := filepath.Join("test-fixtures", "empty") 22 tf := e2e.NewBinary(terraformBin, fixturePath) 23 defer tf.Close() 24 25 stdout, stderr, err := tf.Run("version") 26 if err != nil { 27 t.Errorf("unexpected error: %s", err) 28 } 29 30 if stderr != "" { 31 t.Errorf("unexpected stderr output:\n%s", stderr) 32 } 33 34 wantVersion := fmt.Sprintf("Terraform v%s", tfcore.VersionString()) 35 if !strings.Contains(stdout, wantVersion) { 36 t.Errorf("output does not contain our current version %q:\n%s", wantVersion, stdout) 37 } 38 } 39 40 func TestVersionWithProvider(t *testing.T) { 41 // This is a more elaborate use of "version" that shows the selected 42 // versions of plugins too. 43 t.Parallel() 44 45 // This test reaches out to releases.hashicorp.com to download the 46 // template and null providers, so it can only run if network access is 47 // allowed. 48 skipIfCannotAccessNetwork(t) 49 50 fixturePath := filepath.Join("test-fixtures", "template-provider") 51 tf := e2e.NewBinary(terraformBin, fixturePath) 52 defer tf.Close() 53 54 // Initial run (before "init") should work without error but will not 55 // include the provider version, since we've not "locked" one yet. 56 { 57 stdout, stderr, err := tf.Run("version") 58 if err != nil { 59 t.Errorf("unexpected error: %s", err) 60 } 61 62 if stderr != "" { 63 t.Errorf("unexpected stderr output:\n%s", stderr) 64 } 65 66 wantVersion := fmt.Sprintf("Terraform v%s", tfcore.VersionString()) 67 if !strings.Contains(stdout, wantVersion) { 68 t.Errorf("output does not contain our current version %q:\n%s", wantVersion, stdout) 69 } 70 } 71 72 { 73 _, _, err := tf.Run("init") 74 if err != nil { 75 t.Errorf("unexpected error: %s", err) 76 } 77 } 78 79 // After running init, we additionally include information about the 80 // selected version of the "template" provider. 81 { 82 stdout, stderr, err := tf.Run("version") 83 if err != nil { 84 t.Errorf("unexpected error: %s", err) 85 } 86 87 if stderr != "" { 88 t.Errorf("unexpected stderr output:\n%s", stderr) 89 } 90 91 wantMsg := "+ provider.template v" // we don't know which version we'll get here 92 if !strings.Contains(stdout, wantMsg) { 93 t.Errorf("output does not contain provider information %q:\n%s", wantMsg, stdout) 94 } 95 } 96 }