|
| 1 | +"""Unit tests for process injection utilities.""" |
| 2 | + |
| 3 | +from runpod_flash.core.resources.injection import build_injection_cmd |
| 4 | + |
| 5 | + |
| 6 | +class TestBuildInjectionCmd: |
| 7 | + """Test build_injection_cmd() output format.""" |
| 8 | + |
| 9 | + def test_default_remote_url(self): |
| 10 | + """Test default remote URL generation.""" |
| 11 | + cmd = build_injection_cmd(worker_version="1.1.1") |
| 12 | + |
| 13 | + assert cmd.startswith("bash -c '") |
| 14 | + assert "FW_VER=1.1.1" in cmd |
| 15 | + assert "flash-worker/releases/download/v1.1.1/" in cmd |
| 16 | + assert "bootstrap.sh'" in cmd |
| 17 | + |
| 18 | + def test_custom_tarball_url(self): |
| 19 | + """Test custom tarball URL.""" |
| 20 | + url = "https://example.com/worker.tar.gz" |
| 21 | + cmd = build_injection_cmd(worker_version="2.0.0", tarball_url=url) |
| 22 | + |
| 23 | + assert "FW_VER=2.0.0" in cmd |
| 24 | + assert url in cmd |
| 25 | + |
| 26 | + def test_file_url_for_local_testing(self): |
| 27 | + """Test file:// URL generates local extraction command.""" |
| 28 | + cmd = build_injection_cmd( |
| 29 | + worker_version="1.0.0", |
| 30 | + tarball_url="file:///tmp/flash-worker.tar.gz", |
| 31 | + ) |
| 32 | + |
| 33 | + assert "tar xzf /tmp/flash-worker.tar.gz" in cmd |
| 34 | + assert "curl" not in cmd |
| 35 | + assert "wget" not in cmd |
| 36 | + assert "bootstrap.sh'" in cmd |
| 37 | + |
| 38 | + def test_version_caching_logic(self): |
| 39 | + """Test that version-based cache check is included.""" |
| 40 | + cmd = build_injection_cmd(worker_version="1.1.1") |
| 41 | + |
| 42 | + # Should check .version file |
| 43 | + assert ".version" in cmd |
| 44 | + assert "FW_VER" in cmd |
| 45 | + |
| 46 | + def test_network_volume_caching(self): |
| 47 | + """Test network volume cache path is included.""" |
| 48 | + cmd = build_injection_cmd(worker_version="1.1.1") |
| 49 | + |
| 50 | + assert "/runpod-volume/.flash-worker/" in cmd |
| 51 | + assert "NV_CACHE" in cmd |
| 52 | + |
| 53 | + def test_curl_wget_fallback(self): |
| 54 | + """Test curl/wget fallback logic.""" |
| 55 | + cmd = build_injection_cmd(worker_version="1.0.0") |
| 56 | + |
| 57 | + assert "curl -sSL" in cmd |
| 58 | + assert "wget -qO-" in cmd |
| 59 | + |
| 60 | + def test_default_uses_constants(self): |
| 61 | + """Test that calling with no args uses module-level constants.""" |
| 62 | + from runpod_flash.core.resources.constants import FLASH_WORKER_VERSION |
| 63 | + |
| 64 | + cmd = build_injection_cmd() |
| 65 | + |
| 66 | + assert f"FW_VER={FLASH_WORKER_VERSION}" in cmd |
| 67 | + assert f"v{FLASH_WORKER_VERSION}" in cmd |
| 68 | + |
| 69 | + def test_strip_components_in_remote_extraction(self): |
| 70 | + """Test tar uses --strip-components=1 for remote downloads.""" |
| 71 | + cmd = build_injection_cmd(worker_version="1.0.0") |
| 72 | + |
| 73 | + assert "--strip-components=1" in cmd |
| 74 | + |
| 75 | + def test_strip_components_in_local_extraction(self): |
| 76 | + """Test tar uses --strip-components=1 for local file extraction.""" |
| 77 | + cmd = build_injection_cmd( |
| 78 | + worker_version="1.0.0", |
| 79 | + tarball_url="file:///tmp/fw.tar.gz", |
| 80 | + ) |
| 81 | + |
| 82 | + assert "--strip-components=1" in cmd |
0 commit comments