|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load test_helper |
| 4 | + |
| 5 | +@test "startup healthcheck with start period" { |
| 6 | + # Create a test bundle with startup healthcheck |
| 7 | + local bundle_path="/tmp/test-bundle-startup-hc-$$" |
| 8 | + mkdir -p "$bundle_path" |
| 9 | + |
| 10 | + # Create a config.json with startup healthcheck |
| 11 | + cat > "$bundle_path/config.json" << 'EOF' |
| 12 | +{ |
| 13 | + "ociVersion": "1.0.0", |
| 14 | + "process": { |
| 15 | + "terminal": false, |
| 16 | + "user": { |
| 17 | + "uid": 0, |
| 18 | + "gid": 0 |
| 19 | + }, |
| 20 | + "args": ["/bin/echo", "test"], |
| 21 | + "env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"], |
| 22 | + "cwd": "/" |
| 23 | + }, |
| 24 | + "root": { |
| 25 | + "path": "rootfs", |
| 26 | + "readonly": true |
| 27 | + }, |
| 28 | + "hostname": "test", |
| 29 | + "annotations": { |
| 30 | + "io.podman.healthcheck": "{\"test\":[\"CMD\",\"echo\",\"healthy\"],\"interval\":5,\"timeout\":10,\"start_period\":15,\"retries\":3}" |
| 31 | + } |
| 32 | +} |
| 33 | +EOF |
| 34 | + |
| 35 | + # Test that conmon can parse startup healthcheck configuration |
| 36 | + run $CONMON_BINARY --cid test-container --cuuid test-uuid --runtime /bin/echo --bundle "$bundle_path" --log-path /tmp/test.log --enable-healthcheck --version |
| 37 | + [ "$status" -eq 0 ] |
| 38 | + |
| 39 | + # Cleanup |
| 40 | + rm -rf "$bundle_path" |
| 41 | +} |
| 42 | + |
| 43 | +@test "startup healthcheck without start period" { |
| 44 | + # Create a test bundle with healthcheck but no start period |
| 45 | + local bundle_path="/tmp/test-bundle-no-startup-hc-$$" |
| 46 | + mkdir -p "$bundle_path" |
| 47 | + |
| 48 | + # Create a config.json with healthcheck but no start period |
| 49 | + cat > "$bundle_path/config.json" << 'EOF' |
| 50 | +{ |
| 51 | + "ociVersion": "1.0.0", |
| 52 | + "process": { |
| 53 | + "terminal": false, |
| 54 | + "user": { |
| 55 | + "uid": 0, |
| 56 | + "gid": 0 |
| 57 | + }, |
| 58 | + "args": ["/bin/echo", "test"], |
| 59 | + "env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"], |
| 60 | + "cwd": "/" |
| 61 | + }, |
| 62 | + "root": { |
| 63 | + "path": "rootfs", |
| 64 | + "readonly": true |
| 65 | + }, |
| 66 | + "hostname": "test", |
| 67 | + "annotations": { |
| 68 | + "io.podman.healthcheck": "{\"test\":[\"CMD\",\"echo\",\"healthy\"],\"interval\":5,\"timeout\":10,\"retries\":3}" |
| 69 | + } |
| 70 | +} |
| 71 | +EOF |
| 72 | + |
| 73 | + # Test that conmon can parse healthcheck configuration without start period |
| 74 | + run $CONMON_BINARY --cid test-container --cuuid test-uuid --runtime /bin/echo --bundle "$bundle_path" --log-path /tmp/test.log --enable-healthcheck --version |
| 75 | + [ "$status" -eq 0 ] |
| 76 | + |
| 77 | + # Cleanup |
| 78 | + rm -rf "$bundle_path" |
| 79 | +} |
| 80 | + |
| 81 | +@test "startup healthcheck with invalid JSON" { |
| 82 | + # Create a test bundle with invalid healthcheck JSON |
| 83 | + local bundle_path="/tmp/test-bundle-invalid-hc-$$" |
| 84 | + mkdir -p "$bundle_path" |
| 85 | + |
| 86 | + # Create a config.json with invalid healthcheck JSON |
| 87 | + cat > "$bundle_path/config.json" << 'EOF' |
| 88 | +{ |
| 89 | + "ociVersion": "1.0.0", |
| 90 | + "process": { |
| 91 | + "terminal": false, |
| 92 | + "user": { |
| 93 | + "uid": 0, |
| 94 | + "gid": 0 |
| 95 | + }, |
| 96 | + "args": ["/bin/echo", "test"], |
| 97 | + "env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"], |
| 98 | + "cwd": "/" |
| 99 | + }, |
| 100 | + "root": { |
| 101 | + "path": "rootfs", |
| 102 | + "readonly": true |
| 103 | + }, |
| 104 | + "hostname": "test", |
| 105 | + "annotations": { |
| 106 | + "io.podman.healthcheck": "{\"test\":[\"CMD\",\"echo\",\"healthy\"],\"interval\":5,\"timeout\":10,\"start_period\":15,\"retries\":3" |
| 107 | + } |
| 108 | +} |
| 109 | +EOF |
| 110 | + |
| 111 | + # Test that conmon handles invalid JSON gracefully |
| 112 | + run $CONMON_BINARY --cid test-container --cuuid test-uuid --runtime /bin/echo --bundle "$bundle_path" --log-path /tmp/test.log --enable-healthcheck --version |
| 113 | + [ "$status" -eq 0 ] |
| 114 | + |
| 115 | + # Cleanup |
| 116 | + rm -rf "$bundle_path" |
| 117 | +} |
| 118 | + |
| 119 | +@test "startup healthcheck with missing test command" { |
| 120 | + # Create a test bundle with healthcheck but no test command |
| 121 | + local bundle_path="/tmp/test-bundle-no-test-hc-$$" |
| 122 | + mkdir -p "$bundle_path" |
| 123 | + |
| 124 | + # Create a config.json with healthcheck but no test command |
| 125 | + cat > "$bundle_path/config.json" << 'EOF' |
| 126 | +{ |
| 127 | + "ociVersion": "1.0.0", |
| 128 | + "process": { |
| 129 | + "terminal": false, |
| 130 | + "user": { |
| 131 | + "uid": 0, |
| 132 | + "gid": 0 |
| 133 | + }, |
| 134 | + "args": ["/bin/echo", "test"], |
| 135 | + "env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"], |
| 136 | + "cwd": "/" |
| 137 | + }, |
| 138 | + "root": { |
| 139 | + "path": "rootfs", |
| 140 | + "readonly": true |
| 141 | + }, |
| 142 | + "hostname": "test", |
| 143 | + "annotations": { |
| 144 | + "io.podman.healthcheck": "{\"interval\":5,\"timeout\":10,\"start_period\":15,\"retries\":3}" |
| 145 | + } |
| 146 | +} |
| 147 | +EOF |
| 148 | + |
| 149 | + # Test that conmon handles missing test command gracefully |
| 150 | + run $CONMON_BINARY --cid test-container --cuuid test-uuid --runtime /bin/echo --bundle "$bundle_path" --log-path /tmp/test.log --enable-healthcheck --version |
| 151 | + [ "$status" -eq 0 ] |
| 152 | + |
| 153 | + # Cleanup |
| 154 | + rm -rf "$bundle_path" |
| 155 | +} |
0 commit comments