github.com/maheshbr/terraform@v0.3.1-0.20141020033300-deec7194a3ea/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  )
    12  
    13  const fixtureDir = "./test-fixtures"
    14  
    15  func tempDir(t *testing.T) string {
    16  	dir, err := ioutil.TempDir("", "tf")
    17  	if err != nil {
    18  		t.Fatalf("err: %s", err)
    19  	}
    20  	if err := os.RemoveAll(dir); err != nil {
    21  		t.Fatalf("err: %s", err)
    22  	}
    23  
    24  	return dir
    25  }
    26  
    27  func testConfig(t *testing.T, n string) *config.Config {
    28  	c, err := config.LoadDir(filepath.Join(fixtureDir, n))
    29  	if err != nil {
    30  		t.Fatalf("err: %s", err)
    31  	}
    32  
    33  	return c
    34  }
    35  
    36  func testModule(n string) string {
    37  	p := filepath.Join(fixtureDir, n)
    38  	p, err := filepath.Abs(p)
    39  	if err != nil {
    40  		panic(err)
    41  	}
    42  
    43  	var url url.URL
    44  	url.Scheme = "file"
    45  	url.Path = p
    46  	return url.String()
    47  }
    48  
    49  func testModuleURL(n string) *url.URL {
    50  	u, err := url.Parse(testModule(n))
    51  	if err != nil {
    52  		panic(err)
    53  	}
    54  
    55  	return u
    56  }
    57  
    58  func testStorage(t *testing.T) Storage {
    59  	return &FolderStorage{StorageDir: tempDir(t)}
    60  }