github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/config/module/detect_file_test.go (about)

     1  package module
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestFileDetector(t *testing.T) {
     8  	cases := []struct {
     9  		Input  string
    10  		Output string
    11  	}{
    12  		{"./foo", "file:///pwd/foo"},
    13  		{"./foo?foo=bar", "file:///pwd/foo?foo=bar"},
    14  		{"foo", "file:///pwd/foo"},
    15  		{"/foo", "file:///foo"},
    16  		{"/foo?bar=baz", "file:///foo?bar=baz"},
    17  	}
    18  
    19  	pwd := "/pwd"
    20  	f := new(FileDetector)
    21  	for i, tc := range cases {
    22  		output, ok, err := f.Detect(tc.Input, pwd)
    23  		if err != nil {
    24  			t.Fatalf("err: %s", err)
    25  		}
    26  		if !ok {
    27  			t.Fatal("not ok")
    28  		}
    29  
    30  		if output != tc.Output {
    31  			t.Fatalf("%d: bad: %#v", i, output)
    32  		}
    33  	}
    34  }
    35  
    36  func TestFileDetector_noPwd(t *testing.T) {
    37  	cases := []struct {
    38  		Input  string
    39  		Output string
    40  		Err    bool
    41  	}{
    42  		{"./foo", "", true},
    43  		{"foo", "", true},
    44  		{"/foo", "file:///foo", false},
    45  	}
    46  
    47  	pwd := ""
    48  	f := new(FileDetector)
    49  	for i, tc := range cases {
    50  		output, ok, err := f.Detect(tc.Input, pwd)
    51  		if (err != nil) != tc.Err {
    52  			t.Fatalf("%d: err: %s", i, err)
    53  		}
    54  		if !ok {
    55  			t.Fatal("not ok")
    56  		}
    57  
    58  		if output != tc.Output {
    59  			t.Fatalf("%d: bad: %#v", i, output)
    60  		}
    61  	}
    62  }