Skip to content

Commit

Permalink
Add basic end to end tests
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolai Mishin <[email protected]>
  • Loading branch information
Nmishin committed Mar 1, 2025
1 parent a62b2f9 commit 59b90ad
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#

.PHONY: build test clean
.PHONY: build test e2e_test clean

##@ General
help: ## Display this help.
Expand Down Expand Up @@ -50,6 +50,10 @@ lint: ## Run Go linter
test: ## Run Go tests
go test ./...

##@ E2e_test
e2e_test: build ## Run e2e Go tests
TENV_BIN="$(CURDIR)/build/tenv" go test -tags=e2e ./test/e2e/... -v

##@ Clean
clean:
rm -f ./build
rm -f ./build
68 changes: 68 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//go:build e2e

package e2e

import (
"bytes"
"os/exec"
"os"
"testing"

"github.com/stretchr/testify/require"
)

func TestInstallTerraform(t *testing.T) {
tenvBin := os.Getenv("TENV_BIN")

cmd := exec.Command(tenvBin, "tf", "install", "1.10.5", "-v")

var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &out

err := cmd.Run()

require.NoError(t, err, "Expected no error during the installation process")
require.Contains(t, out.String(), "Installing Terraform 1.10.5")
require.Contains(t, out.String(), "Installation of Terraform 1.10.5 successful")
}

func TestTFenvVersionEnvVariable(t *testing.T) {
tenvBin := os.Getenv("TENV_BIN")

cmd := exec.Command(tenvBin, "tf", "detect")

env := os.Environ()
env = append(env, "TFENV_TERRAFORM_VERSION=1.10.0")
cmd.Env = env

var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &out

err := cmd.Run()

require.NoError(t, err, "Expected no error during the installation process")
require.NotContains(t, out.String(), "Installation of Terraform 1.10.0 successful")
require.Contains(t, out.String(), "Resolved version from TFENV_TERRAFORM_VERSION : 1.10.0")
}

func TestTFenvVersionEnvVariableInstall(t *testing.T) {
tenvBin := os.Getenv("TENV_BIN")

cmd := exec.Command(tenvBin, "tf", "detect", "-i")

env := os.Environ()
env = append(env, "TFENV_TERRAFORM_VERSION=1.10.0")
cmd.Env = env

var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &out

err := cmd.Run()

require.NoError(t, err, "Expected no error during the installation process")
require.Contains(t, out.String(), "Installing Terraform 1.10.0")
require.Contains(t, out.String(), "Installation of Terraform 1.10.0 successful")
}

0 comments on commit 59b90ad

Please sign in to comment.