-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
145 lines (111 loc) · 3.6 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package main
import (
"fmt"
"os/exec"
"strings"
"testing"
)
// Basic integration tests using the legacy BATS test scripts. This ensures the
// new Golang implementation matches the existing Bash implementation.
func TestBatsTests(t *testing.T) {
dir := t.TempDir()
// Build asdf and put in temp directory
buildAsdf(t, dir)
// Run tests with the asdf binary in the temp directory
// Uncomment these as they are implemented
t.Run("current_command", func(t *testing.T) {
runBatsFile(t, dir, "current_command.bats")
})
t.Run("help_command", func(t *testing.T) {
runBatsFile(t, dir, "help_command.bats")
})
t.Run("info_command", func(t *testing.T) {
runBatsFile(t, dir, "info_command.bats")
})
t.Run("install_command", func(t *testing.T) {
runBatsFile(t, dir, "install_command.bats")
})
t.Run("latest_command", func(t *testing.T) {
runBatsFile(t, dir, "latest_command.bats")
})
t.Run("list_command", func(t *testing.T) {
runBatsFile(t, dir, "list_command.bats")
})
t.Run("plugin_add_command", func(t *testing.T) {
runBatsFile(t, dir, "plugin_add_command.bats")
})
t.Run("plugin_extension_command", func(t *testing.T) {
runBatsFile(t, dir, "plugin_extension_command.bats")
})
t.Run("plugin_list_all_command", func(t *testing.T) {
runBatsFile(t, dir, "plugin_list_all_command.bats")
})
t.Run("plugin_remove_command", func(t *testing.T) {
runBatsFile(t, dir, "plugin_remove_command.bats")
})
t.Run("plugin_test_command", func(t *testing.T) {
runBatsFile(t, dir, "plugin_test_command.bats")
})
//t.Run("plugin_update_command", func(t *testing.T) {
// runBatsFile(t, dir, "plugin_update_command.bats")
//})
t.Run("remove_command", func(t *testing.T) {
runBatsFile(t, dir, "remove_command.bats")
})
t.Run("reshim_command", func(t *testing.T) {
runBatsFile(t, dir, "reshim_command.bats")
})
t.Run("shim_env_command", func(t *testing.T) {
runBatsFile(t, dir, "shim_env_command.bats")
})
t.Run("shim_exec", func(t *testing.T) {
runBatsFile(t, dir, "shim_exec.bats")
})
t.Run("shim_versions_command", func(t *testing.T) {
runBatsFile(t, dir, "shim_versions_command.bats")
})
t.Run("uninstall_command", func(t *testing.T) {
runBatsFile(t, dir, "uninstall_command.bats")
})
// Version commands like `asdf global` and `asdf local` aren't going to be
// available, however it would be nice to still support environment variable
// versions, e.g. ASDF_RUBY_VERSION=2.0.0. Some of these tests could be
// enabled and implemented.
//t.Run("version_commands", func(t *testing.T) {
// runBatsFile(t, dir, "version_commands.bats")
//})
t.Run("where_command", func(t *testing.T) {
runBatsFile(t, dir, "where_command.bats")
})
t.Run("which_command", func(t *testing.T) {
runBatsFile(t, dir, "which_command.bats")
})
}
func runBatsFile(t *testing.T, dir, filename string) {
t.Helper()
cmd := exec.Command("bats", "--verbose-run", fmt.Sprintf("test/%s", filename))
// Capture stdout and stderr
var stdout strings.Builder
var stderr strings.Builder
cmd.Stdout = &stdout
cmd.Stderr = &stderr
// Add dir to asdf test variables
asdfTestHome := fmt.Sprintf("BASE_DIR=%s", dir)
asdfBinPath := fmt.Sprintf("ASDF_BIN=%s", dir)
cmd.Env = []string{asdfBinPath, asdfTestHome}
err := cmd.Run()
if err != nil {
// If command fails print both stderr and stdout
fmt.Println("stdout:", stdout.String())
fmt.Println("stderr:", stderr.String())
t.Fatal("bats command failed to run test file successfully")
return
}
}
func buildAsdf(t *testing.T, dir string) {
cmd := exec.Command("go", "build", "-o", dir)
err := cmd.Run()
if err != nil {
t.Fatal("Failed to build asdf")
}
}