-
Notifications
You must be signed in to change notification settings - Fork 870
Expand file tree
/
Copy pathmulti-template.bats
More file actions
198 lines (153 loc) · 5.08 KB
/
multi-template.bats
File metadata and controls
198 lines (153 loc) · 5.08 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# SPDX-FileCopyrightText: Copyright The Lima Authors
# SPDX-License-Identifier: Apache-2.0
load "../helpers/load"
NAME=multi-template
local_setup_file() {
limactl delete --force "$NAME" || :
}
local_teardown_file() {
limactl delete --force "$NAME" || :
}
local_teardown() {
limactl delete --force "$NAME" || :
}
@test 'create with multiple templates merges values' {
# Create base template file (uses /etc/profile as dummy image like create_dummy_instance)
cat > "${BATS_TEST_TMPDIR}/base.yaml" <<'EOF'
images:
- location: /etc/profile
cpus: 3
EOF
# Create override file with additional settings
cat > "${BATS_TEST_TMPDIR}/override.yaml" <<'EOF'
memory: 5GiB
disk: 37GiB
EOF
run -0 limactl create --name "$NAME" "${BATS_TEST_TMPDIR}/base.yaml" "${BATS_TEST_TMPDIR}/override.yaml"
# Verify the base values were used (cpus should be 3 from first template)
run -0 limactl list --format '{{.CPUs}}' "$NAME"
assert_output "3"
# Verify the override values were merged (memory should be from second template)
# 5GiB = 5368709120 bytes
run -0 limactl list --format '{{.Memory}}' "$NAME"
assert_output "5368709120"
}
@test 'first template values take precedence for scalars' {
cat > "${BATS_TEST_TMPDIR}/base.yaml" <<'EOF'
images:
- location: /etc/profile
cpus: 3
memory: 3GiB
EOF
cat > "${BATS_TEST_TMPDIR}/override.yaml" <<'EOF'
cpus: 7
memory: 7GiB
EOF
run -0 limactl create --name "$NAME" "${BATS_TEST_TMPDIR}/base.yaml" "${BATS_TEST_TMPDIR}/override.yaml"
# cpus from first template should win
run -0 limactl list --format '{{.CPUs}}' "$NAME"
assert_output "3"
# memory from first template should win
# 3GiB = 3221225472 bytes
run -0 limactl list --format '{{.Memory}}' "$NAME"
assert_output "3221225472"
}
@test 'relative paths resolve from current directory' {
mkdir -p "${BATS_TEST_TMPDIR}/testdir"
cat > "${BATS_TEST_TMPDIR}/testdir/base.yaml" <<'EOF'
images:
- location: /etc/profile
cpus: 5
EOF
cat > "${BATS_TEST_TMPDIR}/testdir/config.yaml" <<'EOF'
memory: 7GiB
EOF
cd "${BATS_TEST_TMPDIR}/testdir"
run -0 limactl create --name "$NAME" base.yaml config.yaml
run -0 limactl list --format '{{.CPUs}}' "$NAME"
assert_output "5"
# 7GiB = 7516192768 bytes
run -0 limactl list --format '{{.Memory}}' "$NAME"
assert_output "7516192768"
}
@test 'multiple args with existing instance produces error' {
# Create an instance first using stdin
limactl create --name "$NAME" - <<'EOF'
images:
- location: /etc/profile
EOF
cat > "${BATS_TEST_TMPDIR}/extra.yaml" <<'EOF'
cpus: 3
EOF
# Attempting to start the existing instance with additional templates should error
run ! limactl start "$NAME" "${BATS_TEST_TMPDIR}/extra.yaml"
assert_output --partial "cannot specify additional templates"
}
@test 'instance name derived from first template filename' {
# Clean up any stale myinstance from previous runs
limactl delete --force myinstance || :
cat > "${BATS_TEST_TMPDIR}/myinstance.yaml" <<'EOF'
images:
- location: /etc/profile
EOF
cat > "${BATS_TEST_TMPDIR}/override.yaml" <<'EOF'
cpus: 3
EOF
run -0 limactl create "${BATS_TEST_TMPDIR}/myinstance.yaml" "${BATS_TEST_TMPDIR}/override.yaml"
# Instance should be named after first template
run -0 limactl list --format '{{.Name}}'
assert_output --partial "myinstance"
limactl delete --force myinstance || :
}
@test 'explicit --name flag overrides derived name' {
cat > "${BATS_TEST_TMPDIR}/base.yaml" <<'EOF'
images:
- location: /etc/profile
EOF
cat > "${BATS_TEST_TMPDIR}/override.yaml" <<'EOF'
cpus: 5
EOF
run -0 limactl create --name "$NAME" "${BATS_TEST_TMPDIR}/base.yaml" "${BATS_TEST_TMPDIR}/override.yaml"
run -0 limactl list --format '{{.Name}}' "$NAME"
assert_output "$NAME"
}
@test 'three templates merge correctly' {
cat > "${BATS_TEST_TMPDIR}/t1.yaml" <<'EOF'
images:
- location: /etc/profile
cpus: 3
EOF
cat > "${BATS_TEST_TMPDIR}/t2.yaml" <<'EOF'
memory: 5GiB
EOF
cat > "${BATS_TEST_TMPDIR}/t3.yaml" <<'EOF'
disk: 73GiB
EOF
run -0 limactl create --name "$NAME" "${BATS_TEST_TMPDIR}/t1.yaml" "${BATS_TEST_TMPDIR}/t2.yaml" "${BATS_TEST_TMPDIR}/t3.yaml"
run -0 limactl list --format '{{.CPUs}}' "$NAME"
assert_output "3"
# 5GiB = 5368709120 bytes
run -0 limactl list --format '{{.Memory}}' "$NAME"
assert_output "5368709120"
# 73GiB = 78383153152 bytes
run -0 limactl list --format '{{.Disk}}' "$NAME"
assert_output "78383153152"
}
@test 'stdin can be used as one of the templates' {
cat > "${BATS_TEST_TMPDIR}/override.yaml" <<'EOF'
memory: 5GiB
EOF
# Use stdin as the first template, with a file as the second
run -0 limactl create --name "$NAME" - "${BATS_TEST_TMPDIR}/override.yaml" <<'EOF'
images:
- location: /etc/profile
cpus: 7
EOF
# cpus from stdin template should be used
run -0 limactl list --format '{{.CPUs}}' "$NAME"
assert_output "7"
# memory from override file should be merged
# 5GiB = 5368709120 bytes
run -0 limactl list --format '{{.Memory}}' "$NAME"
assert_output "5368709120"
}