File tree Expand file tree Collapse file tree 7 files changed +409
-23
lines changed Expand file tree Collapse file tree 7 files changed +409
-23
lines changed Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: Copyright The Lima Authors
2+ # SPDX-License-Identifier: Apache-2.0
3+
4+ # Create a dummy Lima instance for testing purposes. It cannot be started because it doesn't have an actual image.
5+ # This function intentionally doesn't use create/editflags, but modifies the template with yq instead.
6+ create_dummy_instance () {
7+ local name=$1
8+ local expr=$2
9+
10+ # Template does not validate without an image, and the image must point to a file that exists (for clonefile).
11+ local template=" {images: [location: /etc/profile]}"
12+ if [[ -n $expr ]]; then
13+ template=" $( limactl yq " $expr " <<< " $template" ) "
14+ fi
15+ limactl create --name " $name " - <<< " $template"
16+ }
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: Copyright The Lima Authors
2+ # SPDX-License-Identifier: Apache-2.0
3+
14set -o errexit -o nounset -o pipefail
25
36# Don't run the tests in ~/.lima because they may destroy _config, _templates etc.
@@ -17,8 +20,15 @@ source "$PATH_BATS_ROOT/lib/bats-support/load.bash"
1720source " $PATH_BATS_ROOT /lib/bats-assert/load.bash"
1821source " $PATH_BATS_ROOT /lib/bats-file/load.bash"
1922
23+ source " $PATH_BATS_HELPERS /limactl.bash"
24+ source " $PATH_BATS_HELPERS /logs.bash"
25+
2026bats_require_minimum_version 1.5.0
2127
28+ run_e () {
29+ run --separate-stderr " $@ "
30+ }
31+
2232# If called from foo() this function will call local_foo() if it exist.
2333call_local_function () {
2434 local func
@@ -45,4 +55,10 @@ setup() {
4555}
4656teardown () {
4757 call_local_function
48- }
58+ }
59+
60+ assert_output_lines_count () {
61+ assert_equal " ${# lines[@]} " " $1 "
62+ }
63+
64+
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: Copyright The Lima Authors
2+ # SPDX-License-Identifier: Apache-2.0
3+
4+ # Format the string the way strconv.Quote() would do.
5+ # If the input ends with an ellipsis then no closing quote will be added (and the … will be removed).
6+ quote_msg () {
7+ local quoted
8+ quoted=$( sed -e ' s/\\/\\\\/g' -e ' s/"/\\"/g' -e ' s/^/"/' <<< " $1" )
9+ if [[ $quoted == * … ]]; then
10+ echo " ${quoted% …} "
11+ else
12+ echo " ${quoted} \" "
13+ fi
14+ }
15+
16+ assert_fatal () {
17+ assert_stderr_line --partial " level=fatal msg=$( quote_msg " $1 " ) "
18+ }
19+ assert_error () {
20+ assert_stderr_line --partial " level=error msg=$( quote_msg " $1 " ) "
21+ }
22+ assert_warning () {
23+ assert_stderr_line --partial " level=warning msg=$( quote_msg " $1 " ) "
24+ }
25+ assert_info () {
26+ assert_stderr_line --partial " level=info msg=$( quote_msg " $1 " ) "
27+ }
28+ assert_debug () {
29+ assert_stderr_line --partial " level=debug msg=$( quote_msg " $1 " ) "
30+ }
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: Copyright The Lima Authors
2+ # SPDX-License-Identifier: Apache-2.0
3+
4+ load " ../helpers/load"
5+
6+ @test ' make sure the yq subcommand exists' {
7+ run -0 limactl yq --version
8+ assert_output --regexp ' ^yq .*mikefarah.* version v'
9+ }
10+
11+ @test ' yq can evaluate yq expressions' {
12+ run -0 limactl yq .foo=42 <<< " "
13+ assert_output ' foo: 42'
14+ }
15+
16+ @test ' yq command understand yq options' {
17+ run -0 limactl yq -n -o json -I 0 .foo=42
18+ assert_output ' {"foo":42}'
19+ }
20+
21+ @test ' yq errors set non-zero exit code' {
22+ run -1 limactl yq -n foo
23+ assert_output --partial " invalid input"
24+ }
25+
26+ @test ' yq works as a multi-call binary' {
27+ # multi-call command detection strips all extensions
28+ YQ=" yq.lima.exe"
29+ ln -sf " $( which limactl) " " ${BATS_TEST_TMPDIR} /${YQ} "
30+ export PATH=" $BATS_TEST_TMPDIR :$PATH "
31+
32+ run -0 " $YQ " --version
33+ assert_output --regexp ' ^yq .*mikefarah.* version v'
34+
35+ run -0 " $YQ " -n -o json -I 0 .foo=42
36+ assert_output ' {"foo":42}'
37+ }
You can’t perform that action at this time.
0 commit comments