From 38fc94c2807b5507afad45967cd644a3643c7f5d Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Fri, 25 Sep 2020 10:05:44 +0100 Subject: [PATCH 1/2] Skip linux-dependent tests on all other OSes --- tfexec/internal/e2etest/show_test.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tfexec/internal/e2etest/show_test.go b/tfexec/internal/e2etest/show_test.go index 4268fe74..115438de 100644 --- a/tfexec/internal/e2etest/show_test.go +++ b/tfexec/internal/e2etest/show_test.go @@ -192,12 +192,10 @@ func TestShowStateFile013(t *testing.T) { // Plan files cannot be transferred between different Terraform versions, // so we maintain one fixture per supported version -func TestShowPlanFile012(t *testing.T) { +func TestShowPlanFile012_linux(t *testing.T) { runTestVersions(t, []string{testutil.Latest012}, "non_default_planfile_012", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) { - // plan file fixture was created in Linux, and is - // not compatible with Windows - if runtime.GOOS == "windows" { - t.Skip("plan file created in 0.12 on Linux is not compatible with Windows") + if runtime.GOOS != "linux" { + t.Skip("plan file created in 0.12 on Linux is not compatible with other systems") } providerName := "null" @@ -322,12 +320,10 @@ func TestShowPlanFile013(t *testing.T) { }) } -func TestShowPlanFileRaw012(t *testing.T) { +func TestShowPlanFileRaw012_linux(t *testing.T) { runTestVersions(t, []string{testutil.Latest012}, "non_default_planfile_012", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) { - // plan file fixture was created in Linux, and is - // not compatible with Windows - if runtime.GOOS == "windows" { - t.Skip("plan file created in 0.12 on Linux is not compatible with Windows") + if runtime.GOOS != "linux" { + t.Skip("plan file created in 0.12 on Linux is not compatible with other systems") } // crlf will standardize our line endings for us From 169f865fb1ba9c8d2beb5584ddebfa207f83ffef Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Fri, 25 Sep 2020 10:06:25 +0100 Subject: [PATCH 2/2] Avoid -mod=vendor when there's no vendor folder This accounts for the fact that Terraform no longer vendors dependencies --- tfinstall/git_ref.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tfinstall/git_ref.go b/tfinstall/git_ref.go index 60c01783..71149bd4 100644 --- a/tfinstall/git_ref.go +++ b/tfinstall/git_ref.go @@ -5,7 +5,9 @@ import ( "fmt" "io/ioutil" "log" + "os" "os/exec" + "path/filepath" "runtime" "github.com/go-git/go-git/v5" @@ -72,7 +74,14 @@ func (opt *GitRefOption) ExecPath(ctx context.Context) (string, error) { binFile.Close() } - cmd := exec.CommandContext(ctx, "go", "build", "-mod", "vendor", "-o", binName) + goArgs := []string{"build", "-o", binName} + + vendorDir := filepath.Join(installDir, "vendor") + if fi, err := os.Stat(vendorDir); err == nil && fi.IsDir() { + goArgs = append(goArgs, "-mod", "vendor") + } + + cmd := exec.CommandContext(ctx, "go", goArgs...) cmd.Dir = installDir out, err := cmd.CombinedOutput() log.Print(string(out))