mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
command/e2etest: "terraform version" test
This basic test is here primarily because it's one of the few that can run without reaching out to external services, and so it means our usual test runs will catch situations where the main executable build is somehow broken. The version command itself is not very interesting to test, but it's convenient in that its behavior is very predictable and self-contained.
This commit is contained in:
parent
fee61a44b4
commit
0e0b0d125a
0
command/e2etest/test-fixtures/empty/.exists
Normal file
0
command/e2etest/test-fixtures/empty/.exists
Normal file
35
command/e2etest/version_test.go
Normal file
35
command/e2etest/version_test.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package e2etest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
tfcore "github.com/hashicorp/terraform/terraform"
|
||||||
|
)
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
tf := newTerraform("empty")
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
wantVersion := fmt.Sprintf("Terraform %s", tfcore.VersionString())
|
||||||
|
if strings.Contains(stdout, wantVersion) {
|
||||||
|
t.Errorf("output does not contain our current version %q:\n%s", wantVersion, stdout)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user