github.com/bridgecrewio/terraform@v0.11.12-beta1/config/module/module_test.go (about)

     1  package module
     2  
     3  import (
     4  	"io/ioutil"
     5  	"log"
     6  	"os"
     7  	"path/filepath"
     8  	"testing"
     9  
    10  	"github.com/hashicorp/terraform/config"
    11  	"github.com/hashicorp/terraform/svchost/disco"
    12  )
    13  
    14  func init() {
    15  	if os.Getenv("TF_LOG") == "" {
    16  		log.SetOutput(ioutil.Discard)
    17  	}
    18  }
    19  
    20  const fixtureDir = "./test-fixtures"
    21  
    22  func tempDir(t *testing.T) string {
    23  	t.Helper()
    24  	dir, err := ioutil.TempDir("", "tf")
    25  	if err != nil {
    26  		t.Fatalf("err: %s", err)
    27  	}
    28  	if err := os.RemoveAll(dir); err != nil {
    29  		t.Fatalf("err: %s", err)
    30  	}
    31  
    32  	return dir
    33  }
    34  
    35  func testConfig(t *testing.T, n string) *config.Config {
    36  	t.Helper()
    37  	c, err := config.LoadDir(filepath.Join(fixtureDir, n))
    38  	if err != nil {
    39  		t.Fatalf("err: %s", err)
    40  	}
    41  
    42  	return c
    43  }
    44  
    45  func testStorage(t *testing.T, d *disco.Disco) *Storage {
    46  	t.Helper()
    47  	return NewStorage(tempDir(t), d)
    48  }