terraform/config/module/module_test.go

58 lines
979 B
Go
Raw Normal View History

package module
import (
2014-09-14 03:54:12 +02:00
"io/ioutil"
"net/url"
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"
urlhelper "github.com/hashicorp/terraform/helper/url"
)
const fixtureDir = "./test-fixtures"
2014-09-14 03:54:12 +02:00
func tempDir(t *testing.T) string {
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 {
c, err := config.LoadDir(filepath.Join(fixtureDir, n))
if err != nil {
t.Fatalf("err: %s", err)
}
return c
}
func testModule(n string) string {
p := filepath.Join(fixtureDir, n)
p, err := filepath.Abs(p)
if err != nil {
panic(err)
}
return fmtFileURL(p)
}
2014-09-16 08:52:27 +02:00
func testModuleURL(n string) *url.URL {
u, err := urlhelper.Parse(testModule(n))
2014-09-16 08:52:27 +02:00
if err != nil {
panic(err)
}
return u
}
func testStorage(t *testing.T) Storage {
return &FolderStorage{StorageDir: tempDir(t)}
}