@@ -12,6 +12,7 @@ import (
1212
1313const (
1414 testVersion string = "test"
15+ testExecutable string = "terraputs-test"
1516 expectedEmptyOutput string = `## foo
1617
1718Terraform state outputs.
@@ -23,8 +24,8 @@ Terraform state outputs.
2324)
2425
2526func TestMain (m * testing.M ) {
26- // compile an 'terraputs' for for use in running tests
27- exe := exec .Command ("go" , "build" , "-ldflags" , fmt .Sprintf ("-X main.version=%s" , testVersion ), "-o" , "terraputs" )
27+ // compile a 'terraputs' for use in running tests
28+ exe := exec .Command ("go" , "build" , "-ldflags" , fmt .Sprintf ("-X main.version=%s" , testVersion ), "-o" , testExecutable )
2829 err := exe .Run ()
2930 if err != nil {
3031 os .Exit (1 )
@@ -33,7 +34,7 @@ func TestMain(m *testing.M) {
3334 m .Run ()
3435
3536 // delete the compiled terraputs
36- err = os .Remove ("terraputs" )
37+ err = os .Remove (testExecutable )
3738 if err != nil {
3839 log .Fatal (err )
3940 }
@@ -64,7 +65,7 @@ func TestHelpFlag(t *testing.T) {
6465
6566 for _ , test := range tests {
6667 t .Run (fmt .Sprintf ("when terraputs is passed '%s'" , test .arg ), func (t * testing.T ) {
67- output , err := exec .Command ("./terraputs" , test .arg ).CombinedOutput ()
68+ output , err := exec .Command (fmt . Sprintf ( "./%s" , testExecutable ) , test .arg ).CombinedOutput ()
6869
6970 if err != nil {
7071 t .Errorf ("expected '%s' not to error; got '%v'" , test .arg , err )
@@ -89,7 +90,7 @@ func TestVersionArg(t *testing.T) {
8990
9091 for _ , arg := range args {
9192 t .Run (fmt .Sprintf ("when terraputs is passed '%s'" , arg ), func (t * testing.T ) {
92- output , err := exec .Command ("./terraputs" , arg ).CombinedOutput ()
93+ output , err := exec .Command (fmt . Sprintf ( "./%s" , testExecutable ) , arg ).CombinedOutput ()
9394
9495 if err != nil {
9596 t .Errorf ("expected '%s' not to cause error; got '%v'" , arg , err )
@@ -108,63 +109,67 @@ func TestVersionArg(t *testing.T) {
108109// terraputs < stateFile
109110// cat stateFile | terraputs
110111func TestTerraputs (t * testing.T ) {
112+ command := func (cmd string ) string {
113+ return fmt .Sprintf ("./%s " , testExecutable ) + cmd
114+ }
115+
111116 tests := []struct {
112117 command string
113118 expectedError error
114119 expectedOutput string
115120 }{{
116- command : `./terraputs -state $(cat testdata/basic/show.json)` ,
121+ command : command ( " -state $(cat testdata/basic/show.json)" ) ,
117122 expectedOutput : expectedOutput ("Outputs" ),
118123 }, {
119- command : `./terraputs < testdata/basic/show.json` ,
124+ command : command ( " < testdata/basic/show.json" ) ,
120125 expectedOutput : expectedOutput ("Outputs" ),
121126 }, {
122- command : ` cat testdata/basic/show.json | ./terraputs` ,
127+ command : fmt . Sprintf ( " cat testdata/basic/show.json | ./%s" , testExecutable ) ,
123128 expectedOutput : expectedOutput ("Outputs" ),
124129 }, {
125- command : `./terraputs -state $(cat testdata/basic/show.json) -heading foo` ,
130+ command : command ( " -state $(cat testdata/basic/show.json) -heading foo" ) ,
126131 expectedOutput : expectedOutput ("foo" ),
127132 }, {
128- command : `./terraputs -state $(cat testdata/basic/show.json) -description "A custom description."` ,
133+ command : command ( ` -state $(cat testdata/basic/show.json) -description "A custom description."`) ,
129134 expectedOutput : strings .Replace (expectedOutput ("Outputs" ), "Terraform state outputs" , "A custom description" , 1 ),
130135 }, {
131- command : `./terraputs -state $(cat testdata/nooutputs/show.json) -heading foo` ,
136+ command : command ( " -state $(cat testdata/nooutputs/show.json) -heading foo" ) ,
132137 expectedOutput : expectedEmptyOutput ,
133138 }, {
134- command : `./terraputs -state $(cat testdata/emptyconfig/show.json) -heading foo` ,
139+ command : command ( " -state $(cat testdata/emptyconfig/show.json) -heading foo" ) ,
135140 expectedOutput : expectedEmptyOutput ,
136141 }, {
137- command : `./terraputs -state-file testdata/basic/show.json -heading foo` ,
142+ command : command ( " -state-file testdata/basic/show.json -heading foo" ) ,
138143 expectedOutput : expectedOutput ("foo" ),
139144 }, {
140- command : `./terraputs -state-file testdata/basic/show.json -heading foo -output html` ,
145+ command : command ( " -state-file testdata/basic/show.json -heading foo -output html" ) ,
141146 expectedOutput : expectedHTMLOutput ("foo" ),
142147 }, {
143- command : `./terraputs -state-file testdata/basic/show.json -description "A custom description." -output html` ,
148+ command : command ( ` -state-file testdata/basic/show.json -description "A custom description." -output html`) ,
144149 expectedOutput : strings .Replace (expectedHTMLOutput ("Outputs" ), "Terraform state outputs" , "A custom description" , 1 ),
145150 }, {
146- command : `./terraputs -state-file testdata/nooutputs/show.json -heading foo` ,
151+ command : command ( " -state-file testdata/nooutputs/show.json -heading foo" ) ,
147152 expectedOutput : expectedEmptyOutput ,
148153 }, {
149- command : `./terraputs -state-file testdata/emptyconfig/show.json -heading foo` ,
154+ command : command ( " -state-file testdata/emptyconfig/show.json -heading foo" ) ,
150155 expectedOutput : expectedEmptyOutput ,
151156 }, {
152- command : `./terraputs -state-file testdata/basic/i-do-not-exist.json -heading foo` ,
157+ command : command ( " -state-file testdata/basic/i-do-not-exist.json -heading foo" ) ,
153158 expectedError : errors .New ("exit status 1" ),
154159 expectedOutput : "open testdata/basic/i-do-not-exist.json: no such file or directory" ,
155160 }, {
156- command : `./terraputs -state $(cat testdata/basic/show.json) -state-file testdata/basic/show.json -heading foo` ,
161+ command : command ( " -state $(cat testdata/basic/show.json) -state-file testdata/basic/show.json -heading foo" ) ,
157162 expectedError : errors .New ("exit status 1" ),
158163 expectedOutput : "'-state' and '-state-file' are mutually exclusive; specify just one" ,
159164 }, {
160- command : `./terraputs -state $(cat testdata/basic/show.json) -output foo` ,
165+ command : command ( " -state $(cat testdata/basic/show.json) -output foo" ) ,
161166 expectedError : errors .New ("exit status 1" ),
162167 expectedOutput : "'foo' is not a supported output format. Supported formats: 'md' (default), 'html'" ,
163168 }, {
164- command : `./terraputs -state-file testdata/emptyconfig-1.1.5/show.json -heading foo` ,
169+ command : command ( " -state-file testdata/emptyconfig-1.1.5/show.json -heading foo" ) ,
165170 expectedOutput : expectedEmptyOutput ,
166171 }, {
167- command : `./terraputs -state $(cat testdata/basic-1.1.5/show.json)` ,
172+ command : command ( " -state $(cat testdata/basic-1.1.5/show.json)" ) ,
168173 expectedOutput : expectedOutput ("Outputs" ),
169174 }}
170175
0 commit comments