@@ -20,20 +20,6 @@ local_setup() {
20
20
export LIMA_HOME=" ${LOCAL_LIMA_HOME:? } "
21
21
}
22
22
23
- # In Go templates "{{json .}}" will encode empty maps (e.g. "foo": {}) even if the
24
- # map has the "json:",omitempty" tag. "{{yaml .}}" does omit empty maps, so remove
25
- # them from the JSON output to make it comparable to the YAML one.
26
- #
27
- # TODO should we modify `limactl list` to remove empty maps by default
28
- # since we pass the output through yq anyways?
29
- canonical_json () {
30
- local empty_maps=' .. | select(tag == "!!map" and length == 0)'
31
- while limactl yq --exit-status --input-format json " [${empty_maps} ] | length > 0" <<< " $output" > /dev/null 2>&1 ; do
32
- run -0 limactl yq --input-format json --output-format json --indent 0 " del(${empty_maps} )" <<< " $output"
33
- done
34
-
35
- }
36
-
37
23
@test ' list with no running instances shows a warning and exits without error' {
38
24
export LIMA_HOME=" $BATS_TEST_TMPDIR "
39
25
run_e -0 limactl list
@@ -93,20 +79,19 @@ canonical_json() {
93
79
}
94
80
95
81
@test ' --json is shorthand for --format json' {
96
- run -0 limactl ls --format json foo bar
82
+ run -0 limactl ls foo bar --format json
97
83
format_json=$output
98
84
99
- run -0 limactl ls --json foo bar
85
+ run -0 limactl ls foo bar --json
100
86
assert_output " $format_json "
101
87
}
102
88
103
89
@test ' --format YAML returns YAML documents' {
104
- # save canonical JSON output with empty maps removed, for comparison
90
+ # save JSON output for comparison
105
91
run -0 limactl ls foo bar --format json
106
- canonical_json
107
92
json=$output
108
93
109
- run -0 limactl ls --format yaml foo bar
94
+ run -0 limactl ls foo bar --format yaml
110
95
yaml=$output
111
96
112
97
assert_line --regexp ' ^name: foo'
@@ -121,7 +106,7 @@ canonical_json() {
121
106
run -0 limactl yq --input-format yaml --output-format json --indent 0 " ." <<< " $yaml"
122
107
assert_output_lines_count 2
123
108
124
- # verify it matches the canonical JSON output
109
+ # verify it matches the JSON output
125
110
assert_output " $json "
126
111
127
112
}
@@ -148,14 +133,13 @@ canonical_json() {
148
133
run -0 limactl yq --input-format json --output-format json --indent 0 " ." <<< " $output"
149
134
assert_output_lines_count 2
150
135
151
- # compare to the regular --format json output
136
+ # compare to the plain (uncolorized) json output
152
137
assert_output " $json "
153
138
}
154
139
155
140
@test ' YAML output to terminal is colorized, but semantically identical' {
156
- # save canonical output without colors and empty maps removed
141
+ # save uncolorized JSON output
157
142
run -0 limactl ls foo bar --format json
158
- canonical_json
159
143
json=$output
160
144
161
145
# colorize output even when stdout is not a tty
@@ -179,7 +163,7 @@ canonical_json() {
179
163
run -0 limactl yq --indent 0 --input-format yaml --output-format json " ." <<< " $yaml"
180
164
assert_output_lines_count 2
181
165
182
- # verify it matches the canonical JSON output
166
+ # verify it matches the JSON output
183
167
assert_output " $json "
184
168
}
185
169
0 commit comments