Terratest 在 Mac 上找不到地形
Terratest does not find terraform on Mac
我正在尝试编写一个简单的 go 测试,如下所示
import (
"testing"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
)
func TestCoreInfoOutput(t *testing.T) {
terraformOptions := &terraform.Options{
TerraformDir: "../examples/output.tf",
}
defer terraform.Destroy(t, terraformOptions)
terraform.InitAndApply(t, terraformOptions)
output := terraform.Output(t, terraformOptions, "test_name_prefix")
assert.Equal(t, "dev-use1-hello_world-", output)
}
但是当我 运行 go test my_test.go
我得到以下错误
apply.go:13:
Error Trace: apply.go:13
my_test.go:17
Error: Received unexpected error:
FatalError{Underlying: fork/exec /usr/local/bin/terraform: not a directory}
Test: TestCoreInfoOutput
destroy.go:11:
Error Trace: destroy.go:11
panic.go:615
testing.go:657
apply.go:13
core-info_test.go:17
Error: Received unexpected error:
FatalError{Underlying: fork/exec /usr/local/bin/terraform: not a directory}
Test: my_Test
FAIL
这是文件夹结构
--module
--core-info
--examples
--core-info.tf
--output.tf
--test
my_test.go
我基本上想在我的测试中测试 output.tf 中的输出值。
编辑:
在我将文件更改为文件的目录后,它失败并出现以下错误
goroutine 23 [IO wait]:
internal/poll.runtime_pollWait(0x9804f28, 0x72, 0xffffffffffffffff)
/usr/local/go/src/runtime/netpoll.go:203 +0x55
internal/poll.(*pollDesc).wait(0xc00011c7f8, 0x72, 0x1001, 0x1000, 0xffffffffffffffff)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x45
internal/poll.(*pollDesc).waitRead(...)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Read(0xc00011c7e0, 0xc0001a6000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/internal/poll/fd_unix.go:169 +0x201
os.(*File).read(...)
/usr/local/go/src/os/file_unix.go:263
os.(*File).Read(0xc00011a080, 0xc0001a6000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/os/file.go:116 +0x71
bufio.(*Scanner).Scan(0xc000180300, 0x0)
/usr/local/go/src/bufio/scan.go:213 +0xa4
github.com/gruntwork-io/terratest/modules/shell.readData(0x13ebf20, 0xc00014a7e0, 0xc000180300, 0xc00011ebc0, 0xc00011eb88, 0xc00012d020)
/Users/me/go/src/github.com/gruntwork-io/terratest/modules/shell/command.go:151 +0xc9
created by github.com/gruntwork-io/terratest/modules/shell.readStdoutAndStderr
/Users/me/go/src/github.com/gruntwork-io/terratest/modules/shell/command.go:135 +0x257
FAIL command-line-arguments 600.060s
FAIL
TerraformDir
option 应设置为文件夹路径而不是文件路径。
TerraformDir: "../examples",
"../examples/output.tf"
不是文件夹路径
我正在尝试编写一个简单的 go 测试,如下所示
import (
"testing"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
)
func TestCoreInfoOutput(t *testing.T) {
terraformOptions := &terraform.Options{
TerraformDir: "../examples/output.tf",
}
defer terraform.Destroy(t, terraformOptions)
terraform.InitAndApply(t, terraformOptions)
output := terraform.Output(t, terraformOptions, "test_name_prefix")
assert.Equal(t, "dev-use1-hello_world-", output)
}
但是当我 运行 go test my_test.go
我得到以下错误
apply.go:13:
Error Trace: apply.go:13
my_test.go:17
Error: Received unexpected error:
FatalError{Underlying: fork/exec /usr/local/bin/terraform: not a directory}
Test: TestCoreInfoOutput
destroy.go:11:
Error Trace: destroy.go:11
panic.go:615
testing.go:657
apply.go:13
core-info_test.go:17
Error: Received unexpected error:
FatalError{Underlying: fork/exec /usr/local/bin/terraform: not a directory}
Test: my_Test
FAIL
这是文件夹结构
--module
--core-info
--examples
--core-info.tf
--output.tf
--test
my_test.go
我基本上想在我的测试中测试 output.tf 中的输出值。
编辑:
在我将文件更改为文件的目录后,它失败并出现以下错误
goroutine 23 [IO wait]:
internal/poll.runtime_pollWait(0x9804f28, 0x72, 0xffffffffffffffff)
/usr/local/go/src/runtime/netpoll.go:203 +0x55
internal/poll.(*pollDesc).wait(0xc00011c7f8, 0x72, 0x1001, 0x1000, 0xffffffffffffffff)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x45
internal/poll.(*pollDesc).waitRead(...)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Read(0xc00011c7e0, 0xc0001a6000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/internal/poll/fd_unix.go:169 +0x201
os.(*File).read(...)
/usr/local/go/src/os/file_unix.go:263
os.(*File).Read(0xc00011a080, 0xc0001a6000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/os/file.go:116 +0x71
bufio.(*Scanner).Scan(0xc000180300, 0x0)
/usr/local/go/src/bufio/scan.go:213 +0xa4
github.com/gruntwork-io/terratest/modules/shell.readData(0x13ebf20, 0xc00014a7e0, 0xc000180300, 0xc00011ebc0, 0xc00011eb88, 0xc00012d020)
/Users/me/go/src/github.com/gruntwork-io/terratest/modules/shell/command.go:151 +0xc9
created by github.com/gruntwork-io/terratest/modules/shell.readStdoutAndStderr
/Users/me/go/src/github.com/gruntwork-io/terratest/modules/shell/command.go:135 +0x257
FAIL command-line-arguments 600.060s
FAIL
TerraformDir
option 应设置为文件夹路径而不是文件路径。
TerraformDir: "../examples",
"../examples/output.tf"
不是文件夹路径