github.com/anuaimi/terraform@v0.6.4-0.20150904235404-2bf9aec61da8/config/module/module_test.go (about) 1 package module 2 3 import ( 4 "io/ioutil" 5 "net/url" 6 "os" 7 "path/filepath" 8 "testing" 9 10 "github.com/hashicorp/terraform/config" 11 urlhelper "github.com/hashicorp/terraform/helper/url" 12 ) 13 14 const fixtureDir = "./test-fixtures" 15 16 func tempDir(t *testing.T) string { 17 dir, err := ioutil.TempDir("", "tf") 18 if err != nil { 19 t.Fatalf("err: %s", err) 20 } 21 if err := os.RemoveAll(dir); err != nil { 22 t.Fatalf("err: %s", err) 23 } 24 25 return dir 26 } 27 28 func testConfig(t *testing.T, n string) *config.Config { 29 c, err := config.LoadDir(filepath.Join(fixtureDir, n)) 30 if err != nil { 31 t.Fatalf("err: %s", err) 32 } 33 34 return c 35 } 36 37 func testModule(n string) string { 38 p := filepath.Join(fixtureDir, n) 39 p, err := filepath.Abs(p) 40 if err != nil { 41 panic(err) 42 } 43 return fmtFileURL(p) 44 } 45 46 func testModuleURL(n string) *url.URL { 47 u, err := urlhelper.Parse(testModule(n)) 48 if err != nil { 49 panic(err) 50 } 51 52 return u 53 } 54 55 func testStorage(t *testing.T) Storage { 56 return &FolderStorage{StorageDir: tempDir(t)} 57 }