tfinstall -> hcinstall
diff --git a/tfexec/internal/testutil/logger.go b/tfexec/internal/testutil/logger.go new file mode 100644 index 0000000..f4f2ee5 --- /dev/null +++ b/tfexec/internal/testutil/logger.go
@@ -0,0 +1,15 @@ +package testutil + +import ( + "io/ioutil" + "log" + "os" + "testing" +) + +func TestLogger() *log.Logger { + if testing.Verbose() { + return log.New(os.Stdout, "", log.LstdFlags|log.Lshortfile) + } + return log.New(ioutil.Discard, "", 0) +}
diff --git a/tfexec/internal/testutil/tfcache.go b/tfexec/internal/testutil/tfcache.go index d470ed2..169d913 100644 --- a/tfexec/internal/testutil/tfcache.go +++ b/tfexec/internal/testutil/tfcache.go
@@ -1,11 +1,14 @@ package testutil import ( + "context" "sync" "testing" - "github.com/hashicorp/terraform-exec/tfinstall" - "github.com/hashicorp/terraform-exec/tfinstall/gitref" + "github.com/hashicorp/go-version" + "github.com/hashicorp/hc-install/build" + "github.com/hashicorp/hc-install/product" + "github.com/hashicorp/hc-install/releases" ) const ( @@ -36,16 +39,32 @@ func (tf *TFCache) GitRef(t *testing.T, ref string) string { t.Helper() - return tf.find(t, "gitref:"+ref, func(dir string) tfinstall.ExecPathFinder { - return gitref.Install(ref, "", dir) + + key := "gitref:" + ref + + return tf.find(t, key, func(ctx context.Context) (string, error) { + gr := &build.GitRevision{ + Product: product.Terraform, + Ref: ref, + } + // gr.SetLogger(TestLogger()) + + return gr.Build(ctx) }) } func (tf *TFCache) Version(t *testing.T, v string) string { t.Helper() - return tf.find(t, "v:"+v, func(dir string) tfinstall.ExecPathFinder { - f := tfinstall.ExactVersion(v, dir) - f.UserAgent = appendUserAgent - return f + + key := "v:" + v + + return tf.find(t, key, func(ctx context.Context) (string, error) { + ev := &releases.ExactVersion{ + Product: product.Terraform, + Version: version.Must(version.NewVersion(v)), + } + // ev.SetLogger(TestLogger()) + + return ev.Install(ctx) }) }
diff --git a/tfexec/internal/testutil/tfcache_find.go b/tfexec/internal/testutil/tfcache_find.go index eb03bcb..1578c24 100644 --- a/tfexec/internal/testutil/tfcache_find.go +++ b/tfexec/internal/testutil/tfcache_find.go
@@ -7,11 +7,9 @@ "path/filepath" "strings" "testing" - - "github.com/hashicorp/terraform-exec/tfinstall" ) -func (tf *TFCache) find(t *testing.T, key string, finder func(dir string) tfinstall.ExecPathFinder) string { +func (tf *TFCache) find(t *testing.T, key string, execPathFunc func(context.Context) (string, error)) string { t.Helper() if tf.dir == "" { @@ -43,12 +41,13 @@ ctx, cancelFunc := context.WithCancel(context.Background()) t.Cleanup(cancelFunc) - path, err := tfinstall.Find(ctx, finder(dir)) + execPath, err := execPathFunc(ctx) if err != nil { // panic instead of t.fatal as this is going to affect all downstream tests reusing the cache entry panic(fmt.Sprintf("error installing terraform %q: %s", key, err)) } - tf.execs[key] = path - return path + tf.execs[key] = execPath + + return execPath }
diff --git a/tfexec/terraform.go b/tfexec/terraform.go index 74787af..a41009e 100644 --- a/tfexec/terraform.go +++ b/tfexec/terraform.go
@@ -71,7 +71,7 @@ } if execPath == "" { - err := fmt.Errorf("NewTerraform: please supply the path to a Terraform executable using execPath, e.g. using the tfinstall package.") + err := fmt.Errorf("NewTerraform: please supply the path to a Terraform executable using execPath, e.g. using the github.com/hashicorp/hc-install module.") return nil, &ErrNoSuitableBinary{ err: err, }
diff --git a/tfexec/version_test.go b/tfexec/version_test.go index 17edb94..cc0c916 100644 --- a/tfexec/version_test.go +++ b/tfexec/version_test.go
@@ -9,7 +9,9 @@ "github.com/google/go-cmp/cmp" "github.com/hashicorp/go-version" - "github.com/hashicorp/terraform-exec/tfinstall" + "github.com/hashicorp/hc-install/product" + "github.com/hashicorp/hc-install/releases" + "github.com/hashicorp/terraform-exec/tfexec/internal/testutil" ) func mustVersion(t *testing.T, s string) *version.Version { @@ -205,11 +207,28 @@ } func TestCompatible(t *testing.T) { - tf01226, err := tfinstall.Find(context.Background(), tfinstall.ExactVersion("0.12.26", "")) + ev := &releases.ExactVersion{ + Product: product.Terraform, + Version: version.Must(version.NewVersion("0.12.26")), + } + ev.SetLogger(testutil.TestLogger()) + + ctx := context.Background() + t.Cleanup(func() { ev.Remove(ctx) }) + + tf01226, err := ev.Install(ctx) if err != nil { t.Fatal(err) } - tf013beta3, err := tfinstall.Find(context.Background(), tfinstall.ExactVersion("0.13.0-beta3", "")) + + ev = &releases.ExactVersion{ + Product: product.Terraform, + Version: version.Must(version.NewVersion("0.13.0-beta3")), + } + ev.SetLogger(testutil.TestLogger()) + t.Cleanup(func() { ev.Remove(ctx) }) + + tf013beta3, err := ev.Install(ctx) if err != nil { t.Fatal(err) }