9 // NewLoaderForTests is a variant of NewLoader that is intended to be more
10 // convenient for unit tests.
12 // The loader's modules directory is a separate temporary directory created
13 // for each call. Along with the created loader, this function returns a
14 // cleanup function that should be called before the test completes in order
15 // to remove that temporary directory.
17 // In the case of any errors, t.Fatal (or similar) will be called to halt
18 // execution of the test, so the calling test does not need to handle errors
20 func NewLoaderForTests(t *testing.T) (*Loader, func()) {
23 modulesDir, err := ioutil.TempDir("", "tf-configs")
25 t.Fatalf("failed to create temporary modules dir: %s", err)
30 os.RemoveAll(modulesDir)
33 loader, err := NewLoader(&Config{
34 ModulesDir: modulesDir,
38 t.Fatalf("failed to create config loader: %s", err)
42 return loader, cleanup