|
| 1 | +name: Test Load Docker Image Action |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'load-docker-image/**' |
| 7 | + pull_request: |
| 8 | + paths: |
| 9 | + - 'load-docker-image/**' |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + test-load-docker-image: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Pull and save a test Docker image |
| 21 | + run: | |
| 22 | + docker pull nginx:alpine |
| 23 | + docker save nginx:alpine -o nginx-alpine.tar |
| 24 | + |
| 25 | + - name: Upload test image as artifact |
| 26 | + uses: actions/upload-artifact@v4 |
| 27 | + with: |
| 28 | + name: docker-image |
| 29 | + path: nginx-alpine.tar |
| 30 | + retention-days: 1 |
| 31 | + |
| 32 | + - name: Remove local image to test loading |
| 33 | + run: docker rmi nginx:alpine |
| 34 | + |
| 35 | + - name: Test basic usage |
| 36 | + id: test-basic |
| 37 | + uses: ./load-docker-image |
| 38 | + with: |
| 39 | + artifact-name: 'docker-image' |
| 40 | + image-name: 'nginx' |
| 41 | + tag: 'alpine' |
| 42 | + |
| 43 | + - name: Verify basic test output |
| 44 | + run: | |
| 45 | + echo "Loaded image: ${{ steps.test-basic.outputs.loaded-image }}" |
| 46 | + echo "Image ID: ${{ steps.test-basic.outputs.image-id }}" |
| 47 | + echo "File size: ${{ steps.test-basic.outputs.file-size }}" |
| 48 | + |
| 49 | + # Verify image is loaded |
| 50 | + if ! docker images | grep -q "nginx.*alpine"; then |
| 51 | + echo "❌ Error: Image not loaded correctly" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + |
| 55 | + # Verify outputs are not empty |
| 56 | + if [ -z "${{ steps.test-basic.outputs.loaded-image }}" ]; then |
| 57 | + echo "❌ Error: loaded-image output is empty" |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | + |
| 61 | + if [ -z "${{ steps.test-basic.outputs.image-id }}" ]; then |
| 62 | + echo "❌ Error: image-id output is empty" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + |
| 66 | + if [ -z "${{ steps.test-basic.outputs.file-size }}" ]; then |
| 67 | + echo "❌ Error: file-size output is empty" |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | + |
| 71 | + echo "✅ Basic test passed" |
| 72 | + |
| 73 | + - name: Test custom image path |
| 74 | + run: | |
| 75 | + # Create custom directory and save another image |
| 76 | + mkdir -p custom-path |
| 77 | + docker pull busybox:latest |
| 78 | + docker save busybox:latest -o custom-path/busybox.tar |
| 79 | + |
| 80 | + - name: Upload custom path test image |
| 81 | + uses: actions/upload-artifact@v4 |
| 82 | + with: |
| 83 | + name: custom-image |
| 84 | + path: custom-path/busybox.tar |
| 85 | + retention-days: 1 |
| 86 | + |
| 87 | + - name: Remove busybox image to test loading |
| 88 | + run: docker rmi busybox:latest |
| 89 | + |
| 90 | + - name: Test custom path usage |
| 91 | + id: test-custom |
| 92 | + uses: ./load-docker-image |
| 93 | + with: |
| 94 | + artifact-name: 'custom-image' |
| 95 | + image-path: './custom-download' |
| 96 | + image-name: 'busybox' |
| 97 | + tag: 'latest' |
| 98 | + |
| 99 | + - name: Verify custom path test |
| 100 | + run: | |
| 101 | + echo "Custom loaded image: ${{ steps.test-custom.outputs.loaded-image }}" |
| 102 | + |
| 103 | + # Verify busybox image is loaded |
| 104 | + if ! docker images | grep -q "busybox.*latest"; then |
| 105 | + echo "❌ Error: Custom path image not loaded correctly" |
| 106 | + exit 1 |
| 107 | + fi |
| 108 | + |
| 109 | + echo "✅ Custom path test passed" |
| 110 | + |
| 111 | + - name: Test image verification |
| 112 | + run: | |
| 113 | + # Test that the loaded image works |
| 114 | + docker run --rm nginx:alpine nginx -v |
| 115 | + docker run --rm busybox:latest echo "BusyBox test successful" |
| 116 | + |
| 117 | + echo "✅ Image verification test passed" |
| 118 | + |
| 119 | + - name: Test summary |
| 120 | + run: | |
| 121 | + echo "## Test Results 🧪" >> $GITHUB_STEP_SUMMARY |
| 122 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 123 | + echo "✅ Basic usage test: PASSED" >> $GITHUB_STEP_SUMMARY |
| 124 | + echo "✅ Custom image path test: PASSED" >> $GITHUB_STEP_SUMMARY |
| 125 | + echo "✅ Image verification test: PASSED" >> $GITHUB_STEP_SUMMARY |
| 126 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 127 | + echo "### Loaded Images" >> $GITHUB_STEP_SUMMARY |
| 128 | + echo "- Basic test: \`${{ steps.test-basic.outputs.loaded-image }}\` (ID: ${{ steps.test-basic.outputs.image-id }})" >> $GITHUB_STEP_SUMMARY |
| 129 | + echo "- Custom path test: \`${{ steps.test-custom.outputs.loaded-image }}\` (ID: ${{ steps.test-custom.outputs.image-id }})" >> $GITHUB_STEP_SUMMARY |
| 130 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 131 | + echo "### File Details" >> $GITHUB_STEP_SUMMARY |
| 132 | + echo "- Basic test file size: ${{ steps.test-basic.outputs.file-size }} bytes" >> $GITHUB_STEP_SUMMARY |
| 133 | + echo "- Custom test file size: ${{ steps.test-custom.outputs.file-size }} bytes" >> $GITHUB_STEP_SUMMARY |
| 134 | +
|
| 135 | + test-error-handling: |
| 136 | + runs-on: ubuntu-latest |
| 137 | + |
| 138 | + steps: |
| 139 | + - name: Checkout repository |
| 140 | + uses: actions/checkout@v4 |
| 141 | + |
| 142 | + - name: Test with non-existent artifact (should fail) |
| 143 | + id: test-error |
| 144 | + continue-on-error: true |
| 145 | + uses: ./load-docker-image |
| 146 | + with: |
| 147 | + artifact-name: 'non-existent-artifact' |
| 148 | + |
| 149 | + - name: Verify error handling |
| 150 | + run: | |
| 151 | + if [ "${{ steps.test-error.outcome }}" = "success" ]; then |
| 152 | + echo "❌ Error: Action should have failed with non-existent artifact" |
| 153 | + exit 1 |
| 154 | + fi |
| 155 | + |
| 156 | + echo "✅ Error handling test passed - action correctly failed with non-existent artifact" |
| 157 | +
|
| 158 | + test-with-minikube: |
| 159 | + runs-on: ubuntu-latest |
| 160 | + |
| 161 | + steps: |
| 162 | + - name: Checkout repository |
| 163 | + uses: actions/checkout@v4 |
| 164 | + |
| 165 | + - name: Setup Minikube |
| 166 | + uses: ./setup-minikube |
| 167 | + with: |
| 168 | + minikube-version: 'v1.36.0' |
| 169 | + kubernetes-version: 'v1.33.3' |
| 170 | + |
| 171 | + - name: Pull and save test image |
| 172 | + run: | |
| 173 | + docker pull hello-world:latest |
| 174 | + docker save hello-world:latest -o hello-world.tar |
| 175 | + |
| 176 | + - name: Upload test image for minikube test |
| 177 | + uses: actions/upload-artifact@v4 |
| 178 | + with: |
| 179 | + name: minikube-test-image |
| 180 | + path: hello-world.tar |
| 181 | + retention-days: 1 |
| 182 | + |
| 183 | + - name: Remove local image |
| 184 | + run: docker rmi hello-world:latest |
| 185 | + |
| 186 | + - name: Test loading with minikube |
| 187 | + id: test-minikube |
| 188 | + uses: ./load-docker-image |
| 189 | + with: |
| 190 | + artifact-name: 'minikube-test-image' |
| 191 | + image-name: 'hello-world' |
| 192 | + tag: 'latest' |
| 193 | + minikube: 'true' |
| 194 | + |
| 195 | + - name: Verify minikube loading |
| 196 | + run: | |
| 197 | + echo "Minikube loaded image: ${{ steps.test-minikube.outputs.loaded-image }}" |
| 198 | + |
| 199 | + # Verify image is in minikube |
| 200 | + if ! minikube image ls | grep -q "hello-world"; then |
| 201 | + echo "❌ Error: Image not loaded into minikube" |
| 202 | + exit 1 |
| 203 | + fi |
| 204 | + |
| 205 | + echo "✅ Minikube loading test passed" |
0 commit comments