Skip to content

Commit

Permalink
test: Add tests for two edge cases
Browse files Browse the repository at this point in the history
Add tests for the following cases:

1. The same image is used by more than one compose service.
2. There are more than one version of the same app in the app store.

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
mike-sul committed Sep 18, 2024
1 parent 1cfb1b4 commit e7fcf97
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ check: format
tidy-mod:
go mod tidy -go=$(MODVER)

preload-images:
test/fixtures/preload-images.sh

# target should be run only in the dev container
test-e2e: $(exe)
test-e2e: $(exe) preload-images
go test -v ./...
29 changes: 29 additions & 0 deletions test/fixtures/preload-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

DIR="$(dirname "$(realpath "$0")")"
REGISTRY_URL="registry:5000"
IMAGE_NAME="factory/runner-image"
IMAGE_TAG="v0.1"
IMAGE_URI="${REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_TAG}"

SRC_IMAGE="ghcr.io/foundriesio/busybox:1.36"

# Check if the image exists in the registry
check_image() {
local response=$(curl -s -o /dev/null -w "%{http_code}" \
"https://${REGISTRY_URL}/v2/${IMAGE_NAME}/manifests/${IMAGE_TAG}")

if [[ "$response" == "200" || "$response" == "302" ]]; then
return 0
else
return 1
fi
}

if ! check_image; then
docker pull ${SRC_IMAGE}
docker tag ${SRC_IMAGE} ${IMAGE_URI}
docker push ${IMAGE_URI}
else
echo "Image ${IMAGE_URI} exists in the registry."
fi
69 changes: 69 additions & 0 deletions test/integration/edge_cases_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package e2e_tests

import (
f "github.com/foundriesio/composeapp/test/fixtures"
"testing"
)

func TestAppImageMultiUse(t *testing.T) {
appComposeDef := `
services:
srvs-01:
image: registry:5000/factory/runner-image:v0.1
command: sh -c "while true; do sleep 60; done"
ports:
- 8080:80
srvs-02:
image: registry:5000/factory/runner-image:v0.1
command: sh -c "while true; do sleep 60; done"
`
app := f.NewApp(t, appComposeDef)
app.Publish(t)

app.Pull(t)
defer app.Remove(t)

app.Install(t)
defer app.Uninstall(t)

app.Run(t)
defer app.Stop(t)
app.CheckRunning(t)
}

func TestAppMultipleVersionsInStore(t *testing.T) {
appComposeDef := `
services:
srvs-01:
image: registry:5000/factory/runner-image:v0.1
command: sh -c "while true; do sleep 60; done"
environment:
- VERSION = 0.1
`
appComposeDef02 := `
services:
srvs-01:
image: registry:5000/factory/runner-image:v0.1
command: sh -c "while true; do sleep 60; done"
environment:
- VERSION = 0.2
`
app := f.NewApp(t, appComposeDef)
app.Publish(t)

app02 := f.NewApp(t, appComposeDef02, app.Name)
app02.Publish(t)

app.Pull(t)
defer app.Remove(t)

app02.Pull(t)
defer app02.Remove(t)

app.Install(t)
defer app.Uninstall(t)

app.Up(t)
defer app.Stop(t)
app.CheckRunning(t)
}

0 comments on commit e7fcf97

Please sign in to comment.