diff --git a/Makefile b/Makefile index a6cbda3..c4c8b5e 100644 --- a/Makefile +++ b/Makefile @@ -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 ./... diff --git a/test/fixtures/preload-images.sh b/test/fixtures/preload-images.sh new file mode 100755 index 0000000..2c28d3f --- /dev/null +++ b/test/fixtures/preload-images.sh @@ -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 diff --git a/test/integration/edge_cases_test.go b/test/integration/edge_cases_test.go new file mode 100644 index 0000000..f1fc355 --- /dev/null +++ b/test/integration/edge_cases_test.go @@ -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) +}