at 24.11-pre 2.4 kB view raw
1import ./make-test-python.nix ({ lib, ... }: 2 3{ 4 name = "scrutiny"; 5 meta.maintainers = with lib.maintainers; [ jnsgruk ]; 6 7 nodes = { 8 machine = { self, pkgs, lib, ... }: { 9 services = { 10 scrutiny.enable = true; 11 scrutiny.collector.enable = true; 12 }; 13 14 environment.systemPackages = 15 let 16 seleniumScript = pkgs.writers.writePython3Bin "selenium-script" 17 { 18 libraries = with pkgs.python3Packages; [ selenium ]; 19 } '' 20 from selenium import webdriver 21 from selenium.webdriver.common.by import By 22 from selenium.webdriver.firefox.options import Options 23 from selenium.webdriver.support.ui import WebDriverWait 24 from selenium.webdriver.support import expected_conditions as EC 25 26 options = Options() 27 options.add_argument("--headless") 28 service = webdriver.FirefoxService(executable_path="${lib.getExe pkgs.geckodriver}") # noqa: E501 29 30 driver = webdriver.Firefox(options=options, service=service) 31 driver.implicitly_wait(10) 32 driver.get("http://localhost:8080/web/dashboard") 33 34 wait = WebDriverWait(driver, 10).until( 35 EC.text_to_be_present_in_element( 36 (By.TAG_NAME, "body"), "Drive health at a glance") 37 ) 38 39 body_text = driver.find_element(By.TAG_NAME, "body").text 40 assert "Temperature history for each device" in body_text 41 42 driver.close() 43 ''; 44 in 45 with pkgs; [ curl firefox-unwrapped geckodriver seleniumScript ]; 46 }; 47 }; 48 # This is the test code that will check if our service is running correctly: 49 testScript = '' 50 start_all() 51 52 # Wait for InfluxDB to be available 53 machine.wait_for_unit("influxdb2") 54 machine.wait_for_open_port(8086) 55 56 # Wait for Scrutiny to be available 57 machine.wait_for_unit("scrutiny") 58 machine.wait_for_open_port(8080) 59 60 # Ensure the API responds as we expect 61 output = machine.succeed("curl localhost:8080/api/health") 62 assert output == '{"success":true}' 63 64 # Start the collector service to send some metrics 65 collect = machine.succeed("systemctl start scrutiny-collector.service") 66 67 # Ensure the application is actually rendered by the Javascript 68 machine.succeed("PYTHONUNBUFFERED=1 selenium-script") 69 ''; 70})