MCPcopy Create free account
hub / github.com/coder/coder / Test_absoluteBinaryPath

Function Test_absoluteBinaryPath

provisioner/terraform/serve_internal_test.go:18–98  ·  view source on GitHub ↗

nolint:paralleltest

(t *testing.T)

Source from the content-addressed store, hash-verified

16
17// nolint:paralleltest
18func Test_absoluteBinaryPath(t *testing.T) {
19 tests := []struct {
20 name string
21 terraformVersion string
22 expectedErr error
23 }{
24 {
25 name: "TestCorrectVersion",
26 terraformVersion: "1.3.0",
27 expectedErr: nil,
28 },
29 {
30 name: "TestOldVersion",
31 terraformVersion: "1.0.9",
32 expectedErr: errTerraformMinorVersionMismatch,
33 },
34 {
35 name: "TestNewVersion",
36 terraformVersion: "1.3.0",
37 expectedErr: nil,
38 },
39 {
40 name: "TestNewestNewVersion",
41 terraformVersion: "9.9.9",
42 expectedErr: nil,
43 },
44 {
45 name: "TestMalformedVersion",
46 terraformVersion: "version",
47 expectedErr: xerrors.Errorf("Terraform binary get version failed: malformed version: version"),
48 },
49 }
50 // nolint:paralleltest
51 for _, tt := range tests {
52 t.Run(tt.name, func(t *testing.T) {
53 if runtime.GOOS == "windows" {
54 t.Skip("Dummy terraform executable on Windows requires sh which isn't very practical.")
55 }
56
57 // Create a temp dir with the binary
58 tempDir := t.TempDir()
59 terraformBinaryOutput := fmt.Sprintf(`#!/bin/sh
60 cat <<-EOF
61 {
62 "terraform_version": "%s",
63 "platform": "linux_amd64",
64 "provider_selections": {},
65 "terraform_outdated": false
66 }
67 EOF`, tt.terraformVersion)
68
69 // #nosec
70 err := os.WriteFile(
71 filepath.Join(tempDir, "terraform"),
72 []byte(terraformBinaryOutput),
73 0o770,
74 )
75 require.NoError(t, err)

Callers

nothing calls this directly

Calls 11

ContextFunction · 0.92
systemBinaryFunction · 0.85
SkipMethod · 0.80
SetenvMethod · 0.80
RunMethod · 0.65
TempDirMethod · 0.65
WriteFileMethod · 0.65
ErrorfMethod · 0.45
EqualMethod · 0.45
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected