Skip to content

Commit 9db6c5d

Browse files
committed
Add bats test to cover docker-compose in serve
During #1839 review we decided that having bats test will be very helpful. This PR adds docker-compose bats tests. Also fixes the issue of generating compose file with static name. Fixes: #1873 Signed-off-by: Abhishek Bongale <[email protected]>
1 parent 692a747 commit 9db6c5d

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

ramalama/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
shortnames = Shortnames()
4848

4949

50-
GENERATE_OPTIONS = ["quadlet", "kube", "quadlet/kube"]
50+
GENERATE_OPTIONS = ["quadlet", "kube", "quadlet/kube", "compose"]
5151

5252

5353
class ParsedGenerateInput:

ramalama/compose.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def generate(self) -> PlainFile:
184184

185185
def genfile(name: str, content: str) -> PlainFile:
186186
file_name = "docker-compose.yaml"
187-
print(f"Generating Docker Compose file: {file_name}")
187+
print(f"Generating Compose YAML file: {file_name}")
188188

189189
file = PlainFile(file_name)
190190
file.content = content

test/system/040-serve.bats

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,43 @@ verify_begin=".*run --rm"
444444
rm /tmp/$name.yaml
445445
}
446446

447+
@test "ramalama serve --generate=compose" {
448+
model="smollm:135m"
449+
name="docker-compose"
450+
run_ramalama pull $model
451+
run_ramalama serve --name=$name --port 1234 --generate=compose $model
452+
is "$output" ".*Generating Compose YAML file: ${name}.yaml" "generate .yaml file"
453+
454+
run cat $name.yaml
455+
is "$output" ".*command: .*serve.*" "Should contain serve command"
456+
is "$output" ".*ports:" "Should contain ports section"
457+
is "$output" ".*- \"1234:1234\"" "Should map the container port"
458+
459+
HIP_VISIBLE_DEVICES=99 run_ramalama serve --name=${name} --port 1234 --generate=compose $model
460+
is "$output" ".*Generating Compose YAML file: ${name}.yaml" "generate .yaml file"
461+
462+
run cat $name.yaml
463+
is "$output" ".*environment:" "Should contain environment section"
464+
is "$output" ".*- HIP_VISIBLE_DEVICES=99" "Should contain the HIP_VISIBLE_DEVICES env var"
465+
466+
rm $name.yaml
467+
}
468+
469+
@test "ramalama serve --generate=compose:/tmp" {
470+
model=tiny
471+
name="docker-compose"
472+
run_ramalama pull ${model}
473+
run_ramalama serve --name=$name --port 1234 --generate=compose:/tmp ${model}
474+
is "$output" ".*Generating Compose YAML file: ${name}.yaml" "generate .yaml file in /tmp"
475+
476+
run cat /tmp/$name.yaml
477+
is "$output" ".*command: .*serve.*" "Should contain serve command"
478+
is "$output" ".*ports:" "Should contain ports section"
479+
is "$output" ".*- \"1234:1234\"" "Should map the container port correctly"
480+
481+
rm /tmp/$name.yaml
482+
}
483+
447484
@test "ramalama serve --api llama-stack" {
448485
skip_if_docker
449486
skip_if_nocontainer

test/unit/test_compose.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_compose_genfile(monkeypatch):
200200

201201
assert result.filename == "docker-compose.yaml"
202202
assert result.content == content
203-
assert printed_output == ["Generating Docker Compose file: docker-compose.yaml"]
203+
assert printed_output == ["Generating Compose YAML file: docker-compose.yaml"]
204204

205205

206206
def test_genfile_empty_content(monkeypatch):
@@ -215,7 +215,7 @@ def test_genfile_empty_content(monkeypatch):
215215

216216
assert result.filename == "docker-compose.yaml"
217217
assert result.content == ""
218-
assert printed_output == ["Generating Docker Compose file: docker-compose.yaml"]
218+
assert printed_output == ["Generating Compose YAML file: docker-compose.yaml"]
219219

220220

221221
def test_compose_no_port_arg(monkeypatch):

0 commit comments

Comments
 (0)