Skip to content
Snippets Groups Projects
Select Git revision
  • develop default protected
  • production protected
  • nixpkgs-upgrade-2025-06-16
  • nixpkgs-upgrade-2024-12-23
  • 190-our-regular-updates-fill-up-the-servers-boot-partitions
  • nixpkgs-upgrade-2024-10-14
  • hro-cloud protected
  • 162.flexible-grafana-module
  • nixpkgs-upgrade-2024-05-13
  • nixpkgs-upgrade-2024-04-22
  • nixpkgs-upgrade-2024-03-25
  • nixpkgs-upgrade-2024-03-18
  • nixpkgs-upgrade-2024-03-11
  • nixpkgs-upgrade-2024-03-04
  • 163.jp-to-ben-for-prod
  • nixpkgs-upgrade-2024-02-26
  • 164.grafana-alert-rules
  • 157.authorize-new-hro-key
  • nixpkgs-upgrade-2024-02-19
  • nixpkgs-upgrade-2024-02-12
20 results

unit-tests.nix

Blame
  • unit-tests.nix 1.34 KiB
    # The overall unit test suite for PrivateStorageio NixOS configuration.
    let
      pkgs = import <nixpkgs> { };
    
      # Total the numbers in a list.
      sum = builtins.foldl' (a: b: a + b) 0;
    
      # A helper for loading tests.
      loadTest = moduleUnderTest: testModule:
        (import testModule (pkgs.callPackage moduleUnderTest { }));
    
      # A list of tests to run.  Manually updated for now, alas.  Only tests in
      # this list will be run!
      testModules =
      [ (loadTest ./lib/ini.nix ./lib/tests/test_ini.nix)
      ];
    
      # Count up the tests we're going to run.
      numTests = sum (map (s: builtins.length (builtins.attrNames s)) testModules);
    
      # Convert it into a string for interpolation into the shell script.
      numTestsStr = builtins.toString numTests;
    
      # Run the tests and collect the failures.
      failures = map pkgs.lib.runTests testModules;
    
      # Count the number of failures in each module.
      numFailures = sum (map builtins.length failures);
    
      # Convert the total into a string for easy interpolation into the shell script.
      numFailuresStr = builtins.toString (numFailures);
    
      # Convert the failure information to a string for reporting.
      failuresStr = builtins.toJSON failures;
    in
    pkgs.runCommand "test-results" {} ''
    if [ ${numFailuresStr} -gt 0 ]; then
      echo "Failed ${numFailuresStr} tests"
      echo '${failuresStr}'
      exit 1
    else
      echo '${numTestsStr} tests OK' > $out
    fi
    ''