2022-08-03 13:53:19 +07:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
2022-08-26 19:08:52 +07:00
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
2022-08-03 13:53:19 +07:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gruntwork-io/terratest/modules/docker"
|
2022-09-21 20:10:35 +07:00
|
|
|
"github.com/gruntwork-io/terratest/modules/shell"
|
|
|
|
"github.com/gruntwork-io/terratest/modules/version-checker"
|
2022-08-03 13:53:19 +07:00
|
|
|
)
|
|
|
|
|
2022-09-21 20:10:35 +07:00
|
|
|
func TestToolsVersions(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var tools = []struct {
|
|
|
|
binaryPath string
|
|
|
|
versionConstraint string
|
|
|
|
}{
|
|
|
|
{"ansible", ">= 2.12.6, < 3.0.0"},
|
|
|
|
{"docker", ">= 20.10.17, < 21.0.0"},
|
|
|
|
{"git", ">= 2.37.1, < 3.0.0"},
|
|
|
|
// TODO add more version checks
|
|
|
|
// {"go", ">= 2.37.1, < 3.0.0"},
|
|
|
|
// {"helm", ">= 2.37.1, < 3.0.0"},
|
|
|
|
// {"kubectl", ">= 2.37.1, < 3.0.0"},
|
|
|
|
// {"kustomize", ">= 2.37.1, < 3.0.0"},
|
|
|
|
{"pre-commit", ">= 2.20.0, < 3.0.0"},
|
2022-10-03 11:23:25 +07:00
|
|
|
{"terraform", ">= 1.3.1, < 1.4.0"},
|
2022-09-21 20:10:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tool := range tools {
|
|
|
|
params := version_checker.CheckVersionParams{
|
2022-10-03 12:31:16 +07:00
|
|
|
BinaryPath: tool.binaryPath,
|
2022-09-21 20:10:35 +07:00
|
|
|
VersionConstraint: tool.versionConstraint,
|
2022-10-03 12:31:16 +07:00
|
|
|
WorkingDir: ".",
|
2022-09-21 20:10:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
version_checker.CheckVersion(t, params)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-03 13:53:19 +07:00
|
|
|
func TestToolsContainer(t *testing.T) {
|
2022-09-21 20:10:35 +07:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-08-26 19:08:52 +07:00
|
|
|
image := "nixos/nix"
|
2022-08-30 15:03:20 +07:00
|
|
|
projectRoot, err := filepath.Abs("../")
|
|
|
|
if err != nil {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
2022-08-26 19:08:52 +07:00
|
|
|
|
|
|
|
options := &docker.RunOptions{
|
|
|
|
Remove: true,
|
|
|
|
Volumes: []string{
|
|
|
|
fmt.Sprintf("%s:%s", projectRoot, projectRoot),
|
|
|
|
"homelab-tools-cache:/root/.cache",
|
|
|
|
"homelab-tools-nix:/nix",
|
|
|
|
},
|
|
|
|
OtherOptions: []string{
|
|
|
|
"--workdir", projectRoot,
|
|
|
|
},
|
|
|
|
Command: []string{
|
|
|
|
"nix-shell",
|
2022-10-03 11:49:14 +07:00
|
|
|
"--pure",
|
2022-08-26 19:08:52 +07:00
|
|
|
"--command", "exit",
|
|
|
|
},
|
2022-08-03 13:53:19 +07:00
|
|
|
}
|
|
|
|
|
2022-08-26 19:08:52 +07:00
|
|
|
docker.Run(t, image, options)
|
2022-08-03 13:53:19 +07:00
|
|
|
}
|
2022-09-21 20:10:35 +07:00
|
|
|
|
|
|
|
func TestToolsNixShell(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
projectRoot, err := filepath.Abs("../")
|
|
|
|
if err != nil {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
command := shell.Command{
|
|
|
|
Command: "nix-shell",
|
|
|
|
Args: []string{
|
2022-10-03 11:49:14 +07:00
|
|
|
"--pure",
|
|
|
|
"--command", "exit",
|
2022-09-21 20:10:35 +07:00
|
|
|
},
|
|
|
|
WorkingDir: projectRoot,
|
|
|
|
}
|
|
|
|
|
|
|
|
shell.RunCommand(t, command)
|
|
|
|
}
|