Skip to content

Commit 11f0fd9

Browse files
committed
Add e2e test for static port forwards
Signed-off-by: Praful Khanduri <[email protected]>
1 parent 34f00b0 commit 11f0fd9

File tree

6 files changed

+98
-3
lines changed

6 files changed

+98
-3
lines changed

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,24 @@ jobs:
612612
sudo chown $(whoami) /dev/kvm
613613
- name: Smoke test
614614
run: limactl start --tty=false
615+
616+
static-port-forwarding:
617+
name: "Static Port Forwarding Tests"
618+
runs-on: ubuntu-24.04
619+
timeout-minutes: 30
620+
steps:
621+
- uses: actions/checkout@v4
622+
with:
623+
fetch-depth: 1
624+
- name: Install dependencies
625+
run: |
626+
sudo apt-get update
627+
sudo apt-get install -y qemu-utils qemu-system-x86 ovmf curl
628+
- name: Make
629+
run: make
630+
- name: Install
631+
run: sudo make install
632+
- name: Run plain mode static port forwarding test
633+
run: bash hack/test-plain-static-port-forward.sh
634+
- name: Run non-plain mode static port forwarding test
635+
run: bash hack/test-nonplain-static-port-forward.sh

cmd/limactl/editflags/editflags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) {
288288
if len(parts) != 2 {
289289
return "", fmt.Errorf("invalid static port forward format %q, expected HOST:GUEST", s)
290290
}
291-
hostPort := strings.TrimSpace(parts[0])
292-
guestPort := strings.TrimSpace(parts[1])
293-
expr += fmt.Sprintf(`{"hostPort": %s, "guestPort": %s, "static": true}`, hostPort, guestPort)
291+
guestPort := strings.TrimSpace(parts[0])
292+
hostPort := strings.TrimSpace(parts[1])
293+
expr += fmt.Sprintf(`{"guestPort": %s, "hostPort": %s}`, guestPort, hostPort)
294294
if i < len(ss)-1 {
295295
expr += ","
296296
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
INSTANCE=nonplain-static-port-forward
5+
TEMPLATE=hack/test-templates/nonplain-static-port-forward.yaml
6+
7+
limactl delete -f $INSTANCE || true
8+
9+
limactl start --name=$INSTANCE --tty=false $TEMPLATE
10+
11+
limactl shell $INSTANCE -- bash -c 'until [ -e /run/nginx.pid ]; do sleep 1; done'
12+
13+
curl -sSf http://127.0.0.1:9090 | grep -i 'nginx' && echo 'nginx port forwarding works!'
14+
15+
limactl delete -f $INSTANCE
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
INSTANCE=plain-static-port-forward
5+
TEMPLATE=hack/test-templates/plain-static-port-forward.yaml
6+
7+
limactl delete -f $INSTANCE || true
8+
9+
limactl start --name=$INSTANCE --tty=false $TEMPLATE
10+
11+
limactl shell $INSTANCE -- bash -c 'until [ -e /run/nginx.pid ]; do sleep 1; done'
12+
13+
curl -sSf http://127.0.0.1:9090 | grep -i 'nginx' && echo 'nginx port forwarding works!'
14+
15+
if curl -sSf http://127.0.0.1:9080; then
16+
echo 'ERROR: Port 9080 should not be forwarded in plain mode!'
17+
exit 1
18+
else
19+
echo 'Port 9080 is correctly NOT forwarded in plain mode.'
20+
fi
21+
22+
limactl delete -f $INSTANCE
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
images:
2+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img"
3+
arch: "x86_64"
4+
5+
provision:
6+
- mode: system
7+
script: |
8+
apt-get update
9+
apt-get install -y nginx
10+
systemctl enable nginx
11+
systemctl start nginx
12+
13+
portForwards:
14+
- guestPort: 80
15+
hostPort: 9090
16+
static: true
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
images:
2+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img"
3+
arch: "x86_64"
4+
5+
plain: true
6+
7+
provision:
8+
- mode: system
9+
script: |
10+
apt-get update
11+
apt-get install -y nginx
12+
systemctl enable nginx
13+
systemctl start nginx
14+
15+
portForwards:
16+
- guestPort: 80
17+
hostPort: 9090
18+
static: true
19+
- guestPort: 9080
20+
hostPort: 9080
21+
static: false

0 commit comments

Comments
 (0)