-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f12ff0
commit 729720f
Showing
17 changed files
with
116 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// +build go1.14 | ||
|
||
package testutil | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
) | ||
|
||
// TODO: Remove once we drop support for Go <1.15 | ||
// in favour of native t.TempDir() | ||
func TempDir(t *testing.T) string { | ||
dir, err := ioutil.TempDir("", "tf") | ||
if err != nil { | ||
t.Fatalf("error creating temporary test directory: %s", err) | ||
} | ||
|
||
t.Cleanup(func() { | ||
os.RemoveAll(dir) | ||
}) | ||
|
||
return dir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// +build go1.14 | ||
|
||
package testutil | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"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 { | ||
t.Helper() | ||
|
||
if tf.dir == "" { | ||
// panic instead of t.fatal as this is going to affect all downstream tests reusing the cache entry | ||
panic("installDir not yet configured") | ||
} | ||
|
||
tf.Lock() | ||
defer tf.Unlock() | ||
|
||
if path, ok := tf.execs[key]; ok { | ||
return path | ||
} | ||
|
||
keyDir := key | ||
keyDir = strings.ReplaceAll(keyDir, ":", "-") | ||
keyDir = strings.ReplaceAll(keyDir, "/", "-") | ||
|
||
dir := filepath.Join(tf.dir, keyDir) | ||
|
||
t.Logf("caching exec %q in dir %q", key, dir) | ||
|
||
err := os.MkdirAll(dir, 0777) | ||
if err != nil { | ||
// panic instead of t.fatal as this is going to affect all downstream tests reusing the cache entry | ||
panic(fmt.Sprintf("unable to mkdir %q: %s", dir, err)) | ||
} | ||
|
||
ctx, cancelFunc := context.WithCancel(context.Background()) | ||
t.Cleanup(cancelFunc) | ||
|
||
path, err := tfinstall.Find(ctx, finder(dir)) | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// +build !go1.14 | ||
|
||
package testutil | ||
|
||
import ( | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-exec/tfinstall" | ||
) | ||
|
||
func (tf *TFCache) find(t *testing.T, key string, finder func(dir string) tfinstall.ExecPathFinder) string { | ||
panic("not implemented for " + runtime.Version()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.