|  | 
|  | 1 | +{ pkgs, ... }: | 
|  | 2 | +let | 
|  | 3 | +  module = import ../modules/nixos/nixos-passthru-cache; | 
|  | 4 | +in | 
|  | 5 | +pkgs.nixosTest { | 
|  | 6 | +  name = "nixos-passthru-cache-smoke"; | 
|  | 7 | + | 
|  | 8 | +  nodes.machine = { pkgs, ... }: { | 
|  | 9 | +    imports = [ module ]; | 
|  | 10 | + | 
|  | 11 | +    # Fake upstream served by the same nginx on 127.0.0.1:1234 | 
|  | 12 | +    services.nginx.virtualHosts."fake-upstream" = { | 
|  | 13 | +      listen = [{ addr = "127.0.0.1"; port = 1234; ssl = false; }]; | 
|  | 14 | +      serverName = "fake-upstream"; | 
|  | 15 | +      locations."/".extraConfig = '' | 
|  | 16 | +        add_header Cache-Control "max-age=3600"; | 
|  | 17 | +        add_header X-Fake-Upstream 1; | 
|  | 18 | +        return 200 "hello from upstream\n"; | 
|  | 19 | +      ''; | 
|  | 20 | +    }; | 
|  | 21 | + | 
|  | 22 | +    services.nixos-passthru-cache = { | 
|  | 23 | +      enable = true; | 
|  | 24 | +      forceSSL = false; | 
|  | 25 | +      hostName = "cache.local"; | 
|  | 26 | +      upstream = "http://127.0.0.1:1234"; | 
|  | 27 | +      stats.enable = true; | 
|  | 28 | +    }; | 
|  | 29 | + | 
|  | 30 | +    # Keep things simple for the test | 
|  | 31 | +    networking.firewall.enable = false; | 
|  | 32 | +    environment.systemPackages = [ pkgs.curl ]; | 
|  | 33 | +  }; | 
|  | 34 | + | 
|  | 35 | +  testScript = '' | 
|  | 36 | +    start_all() | 
|  | 37 | +    machine.wait_for_unit("nginx.service") | 
|  | 38 | +    machine.wait_for_open_port(80) | 
|  | 39 | +    machine.wait_for_open_port(1234) | 
|  | 40 | +
 | 
|  | 41 | +    # nix-cache-info served with correct content-type and content | 
|  | 42 | +    machine.succeed("curl -sSfI http://localhost/nix-cache-info | grep -qi 'content-type: text/x-nix-cache-info'") | 
|  | 43 | +    machine.succeed("curl -sSf http://localhost/nix-cache-info | grep -q '^StoreDir:'") | 
|  | 44 | +
 | 
|  | 45 | +    # Cache MISS then HIT against fake upstream | 
|  | 46 | +    machine.succeed("curl -sSfi http://localhost/foo | tee /tmp/res1 | grep -qi '^X-Cache-Status: MISS' || (echo 'expected MISS' && cat /tmp/res1 && false)") | 
|  | 47 | +    machine.succeed("curl -sSfi http://localhost/foo | tee /tmp/res2 | grep -qi '^X-Cache-Status: HIT' || (echo 'expected HIT' && cat /tmp/res2 && false)") | 
|  | 48 | +
 | 
|  | 49 | +    # VTS status page reachable (HTML) | 
|  | 50 | +    machine.succeed("curl -sSfI http://localhost/status | grep -q '200'") | 
|  | 51 | +  ''; | 
|  | 52 | +} | 
0 commit comments