Терратест не находит терраформ на Mac - PullRequest
0 голосов
/ 21 марта 2020

Я пытаюсь написать простой 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

1 Ответ

0 голосов
/ 24 марта 2020

TerraformDir параметр должен быть указан как путь к папке, а не как путь к файлу.

    TerraformDir: "../examples",

"../examples/output.tf" не является путем к папке

...