@@ -10,42 +10,43 @@ import (
10
10
"testing"
11
11
12
12
"github.com/stretchr/testify/require"
13
+ "golang.org/x/xerrors"
13
14
)
14
15
15
16
// nolint:paralleltest
16
- func Test_getAbsoluteBinaryPath (t * testing.T ) {
17
+ func Test_absoluteBinaryPath (t * testing.T ) {
17
18
type args struct {
18
19
ctx context.Context
19
20
}
20
21
tests := []struct {
21
22
name string
22
23
args args
23
24
terraformVersion string
24
- expectedOk bool
25
+ expectedErr error
25
26
}{
26
27
{
27
28
name : "TestCorrectVersion" ,
28
29
args : args {ctx : context .Background ()},
29
30
terraformVersion : "1.1.9" ,
30
- expectedOk : true ,
31
+ expectedErr : nil ,
31
32
},
32
33
{
33
34
name : "TestOldVersion" ,
34
35
args : args {ctx : context .Background ()},
35
36
terraformVersion : "1.0.9" ,
36
- expectedOk : false ,
37
+ expectedErr : xerrors . Errorf ( "Terraform binary minor version mismatch." ) ,
37
38
},
38
39
{
39
40
name : "TestNewVersion" ,
40
41
args : args {ctx : context .Background ()},
41
42
terraformVersion : "1.2.9" ,
42
- expectedOk : false ,
43
+ expectedErr : xerrors . Errorf ( "Terraform binary minor version mismatch." ) ,
43
44
},
44
45
{
45
46
name : "TestMalformedVersion" ,
46
47
args : args {ctx : context .Background ()},
47
48
terraformVersion : "version" ,
48
- expectedOk : false ,
49
+ expectedErr : xerrors . Errorf ( "Terraform binary get version failed: Malformed version: version" ) ,
49
50
},
50
51
}
51
52
// nolint:paralleltest
@@ -80,16 +81,22 @@ func Test_getAbsoluteBinaryPath(t *testing.T) {
80
81
t .Setenv ("PATH" , strings .Join ([]string {tempDir , pathVariable }, ":" ))
81
82
82
83
var expectedAbsoluteBinary string
83
- if tt .expectedOk {
84
+ if tt .expectedErr == nil {
84
85
expectedAbsoluteBinary = filepath .Join (tempDir , "terraform" )
85
86
}
86
87
87
- actualAbsoluteBinary , actualOk := getAbsoluteBinaryPath (tt .args .ctx )
88
+ actualAbsoluteBinary , actualErr := absoluteBinaryPath (tt .args .ctx )
88
89
if actualAbsoluteBinary != expectedAbsoluteBinary {
89
90
t .Errorf ("getAbsoluteBinaryPath() absoluteBinaryPath, actual = %v, expected %v" , actualAbsoluteBinary , expectedAbsoluteBinary )
90
91
}
91
- if actualOk != tt .expectedOk {
92
- t .Errorf ("getAbsoluteBinaryPath() ok, actual = %v, expected %v" , actualOk , tt .expectedOk )
92
+ if tt .expectedErr == nil {
93
+ if actualErr != nil {
94
+ t .Errorf ("getAbsoluteBinaryPath() error, actual = %v, expected %v" , actualErr .Error (), tt .expectedErr )
95
+ }
96
+ } else {
97
+ if actualErr .Error () != tt .expectedErr .Error () {
98
+ t .Errorf ("getAbsoluteBinaryPath() error, actual = %v, expected %v" , actualErr .Error (), tt .expectedErr .Error ())
99
+ }
93
100
}
94
101
})
95
102
}
0 commit comments