lol

nixosTests.scrutiny: migrate to runTest

Part of #386873

+84 -86
+1 -1
nixos/tests/all-tests.nix
··· 1051 1051 scaphandre = handleTest ./scaphandre.nix {}; 1052 1052 schleuder = handleTest ./schleuder.nix {}; 1053 1053 scion-freestanding-deployment = handleTest ./scion/freestanding-deployment {}; 1054 - scrutiny = handleTest ./scrutiny.nix {}; 1054 + scrutiny = runTest ./scrutiny.nix; 1055 1055 sddm = handleTest ./sddm.nix {}; 1056 1056 sdl3 = handleTest ./sdl3.nix { }; 1057 1057 seafile = handleTest ./seafile.nix {};
+83 -85
nixos/tests/scrutiny.nix
··· 1 - import ./make-test-python.nix ( 2 - { lib, ... }: 1 + { lib, ... }: 3 2 4 - { 5 - name = "scrutiny"; 6 - meta.maintainers = with lib.maintainers; [ jnsgruk ]; 3 + { 4 + name = "scrutiny"; 5 + meta.maintainers = with lib.maintainers; [ jnsgruk ]; 7 6 8 - nodes = { 9 - machine = 10 - { 11 - self, 12 - pkgs, 13 - lib, 14 - ... 15 - }: 16 - { 17 - services = { 18 - scrutiny = { 19 - enable = true; 20 - settings = { 21 - notify.urls = [ 22 - { 23 - _secret = pkgs.writeText "notify-script" "script://${pkgs.writeShellScript "touch-test-file" '' 24 - echo "HelloWorld" > /run/scrutiny/hello 25 - ''}"; 26 - } 27 - ]; 28 - }; 7 + nodes = { 8 + machine = 9 + { 10 + self, 11 + pkgs, 12 + lib, 13 + ... 14 + }: 15 + { 16 + services = { 17 + scrutiny = { 18 + enable = true; 19 + settings = { 20 + notify.urls = [ 21 + { 22 + _secret = pkgs.writeText "notify-script" "script://${pkgs.writeShellScript "touch-test-file" '' 23 + echo "HelloWorld" > /run/scrutiny/hello 24 + ''}"; 25 + } 26 + ]; 29 27 }; 30 - scrutiny.collector.enable = true; 31 28 }; 29 + scrutiny.collector.enable = true; 30 + }; 32 31 33 - environment.systemPackages = 34 - let 35 - seleniumScript = 36 - pkgs.writers.writePython3Bin "selenium-script" 37 - { 38 - libraries = with pkgs.python3Packages; [ selenium ]; 39 - } 40 - '' 41 - from selenium import webdriver 42 - from selenium.webdriver.common.by import By 43 - from selenium.webdriver.firefox.options import Options 44 - from selenium.webdriver.support.ui import WebDriverWait 45 - from selenium.webdriver.support import expected_conditions as EC 32 + environment.systemPackages = 33 + let 34 + seleniumScript = 35 + pkgs.writers.writePython3Bin "selenium-script" 36 + { 37 + libraries = with pkgs.python3Packages; [ selenium ]; 38 + } 39 + '' 40 + from selenium import webdriver 41 + from selenium.webdriver.common.by import By 42 + from selenium.webdriver.firefox.options import Options 43 + from selenium.webdriver.support.ui import WebDriverWait 44 + from selenium.webdriver.support import expected_conditions as EC 46 45 47 - options = Options() 48 - options.add_argument("--headless") 49 - service = webdriver.FirefoxService(executable_path="${lib.getExe pkgs.geckodriver}") # noqa: E501 46 + options = Options() 47 + options.add_argument("--headless") 48 + service = webdriver.FirefoxService(executable_path="${lib.getExe pkgs.geckodriver}") # noqa: E501 50 49 51 - driver = webdriver.Firefox(options=options, service=service) 52 - driver.implicitly_wait(10) 53 - driver.get("http://localhost:8080/web/dashboard") 50 + driver = webdriver.Firefox(options=options, service=service) 51 + driver.implicitly_wait(10) 52 + driver.get("http://localhost:8080/web/dashboard") 54 53 55 - wait = WebDriverWait(driver, 10).until( 56 - EC.text_to_be_present_in_element( 57 - (By.TAG_NAME, "body"), "Drive health at a glance") 58 - ) 54 + wait = WebDriverWait(driver, 10).until( 55 + EC.text_to_be_present_in_element( 56 + (By.TAG_NAME, "body"), "Drive health at a glance") 57 + ) 59 58 60 - body_text = driver.find_element(By.TAG_NAME, "body").text 61 - assert "Temperature history for each device" in body_text 59 + body_text = driver.find_element(By.TAG_NAME, "body").text 60 + assert "Temperature history for each device" in body_text 62 61 63 - driver.close() 64 - ''; 65 - in 66 - with pkgs; 67 - [ 68 - curl 69 - firefox-unwrapped 70 - geckodriver 71 - seleniumScript 72 - ]; 73 - }; 74 - }; 75 - # This is the test code that will check if our service is running correctly: 76 - testScript = '' 77 - start_all() 62 + driver.close() 63 + ''; 64 + in 65 + with pkgs; 66 + [ 67 + curl 68 + firefox-unwrapped 69 + geckodriver 70 + seleniumScript 71 + ]; 72 + }; 73 + }; 74 + # This is the test code that will check if our service is running correctly: 75 + testScript = '' 76 + start_all() 78 77 79 - # Wait for Scrutiny to be available 80 - machine.wait_for_unit("scrutiny") 81 - machine.wait_for_open_port(8080) 78 + # Wait for Scrutiny to be available 79 + machine.wait_for_unit("scrutiny") 80 + machine.wait_for_open_port(8080) 82 81 83 - # Ensure the API responds as we expect 84 - output = machine.succeed("curl localhost:8080/api/health") 85 - assert output == '{"success":true}' 82 + # Ensure the API responds as we expect 83 + output = machine.succeed("curl localhost:8080/api/health") 84 + assert output == '{"success":true}' 86 85 87 - # Start the collector service to send some metrics 88 - collect = machine.succeed("systemctl start scrutiny-collector.service") 86 + # Start the collector service to send some metrics 87 + collect = machine.succeed("systemctl start scrutiny-collector.service") 89 88 90 - # Ensure the application is actually rendered by the Javascript 91 - machine.succeed("PYTHONUNBUFFERED=1 selenium-script") 89 + # Ensure the application is actually rendered by the Javascript 90 + machine.succeed("PYTHONUNBUFFERED=1 selenium-script") 92 91 93 - # Test notification and genJqSecretsReplacementSnippet 94 - machine.succeed("curl -X POST http://localhost:8080/api/health/notify") 95 - machine.wait_for_file("/run/scrutiny/hello") 96 - output = machine.succeed("cat /run/scrutiny/hello") 97 - assert "HelloWorld" in output 98 - ''; 99 - } 100 - ) 92 + # Test notification and genJqSecretsReplacementSnippet 93 + machine.succeed("curl -X POST http://localhost:8080/api/health/notify") 94 + machine.wait_for_file("/run/scrutiny/hello") 95 + output = machine.succeed("cat /run/scrutiny/hello") 96 + assert "HelloWorld" in output 97 + ''; 98 + }