terraform/config/module/module_test.go

49 lines
813 B
Go
Raw Normal View History

package module
import (
2014-09-14 03:54:12 +02:00
"io/ioutil"
"log"
2014-09-14 03:54:12 +02:00
"os"
"path/filepath"
2014-09-14 03:54:12 +02:00
"testing"
2014-09-14 23:46:45 +02:00
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/svchost/disco"
)
func init() {
if os.Getenv("TF_LOG") == "" {
log.SetOutput(ioutil.Discard)
}
}
const fixtureDir = "./test-fixtures"
2014-09-14 03:54:12 +02:00
func tempDir(t *testing.T) string {
t.Helper()
2014-09-14 03:54:12 +02:00
dir, err := ioutil.TempDir("", "tf")
if err != nil {
t.Fatalf("err: %s", err)
}
if err := os.RemoveAll(dir); err != nil {
t.Fatalf("err: %s", err)
}
return dir
}
2014-09-14 23:46:45 +02:00
func testConfig(t *testing.T, n string) *config.Config {
t.Helper()
2014-09-14 23:46:45 +02:00
c, err := config.LoadDir(filepath.Join(fixtureDir, n))
if err != nil {
t.Fatalf("err: %s", err)
}
return c
}
func testStorage(t *testing.T, d *disco.Disco) *Storage {
t.Helper()
return NewStorage(tempDir(t), d, nil)
}