{ lib, pkgs, ... }: let cilib = import ./../lib {inherit lib pkgs;}; in { nixtest.suites."CI Lib" = { pos = __curPos; tests = let inherit (cilib.jobDeps) mkJobDeps; inherit (cilib.jobRun) mkJobRun; inherit (cilib.jobPatch) mkJobPatched; inherit (cilib.pipeline) mkPipeline; deps = mkJobDeps { key = "test"; job = { nix.deps = [pkgs.hello]; variables.TEST = "${pkgs.curl}"; }; }; in [ { name = "jobDeps"; type = "script"; script = # sh '' export PATH=${lib.makeBinPath [pkgs.gnugrep]} grep -q "/nix/store" ${deps} grep -q 'hello/bin:$PATH' ${deps} grep -q "export TEST=" ${deps} grep -q "curl" ${deps} ''; } { name = "jobRun"; type = "script"; script = let run = mkJobRun { key = "test"; job.script = ["hello"]; jobDeps = deps; }; in # sh '' export PATH=${lib.makeBinPath [pkgs.gnugrep]} grep -q "sandbox-helper" ${run}/bin/gitlab-ci-job:test grep -q "gitlab-ci-job-test-raw" ${run}/bin/gitlab-ci-job:test grep -q "gitlab-ci-job-deps-test" ${run.passthru.actualJobScript} grep -q "Running script..." ${run.passthru.actualJobScript} grep -q "hello" ${run.passthru.actualJobScript} ''; } { name = "jobPatched nix disabled"; expected = {}; actual = mkJobPatched { key = "test"; pipeline_name = "test"; job.nix.enable = false; }; } { name = "jobPatched without runner cache"; expected = { after_script = ["finalize_nix_ci"]; before_script = ["source setup_nix_ci \"gitlab-ci:pipeline:test:job-deps:test\""]; }; actual = mkJobPatched { key = "test"; pipeline_name = "test"; job.nix = { enable = true; enable-runner-cache = false; }; }; } { name = "jobPatched with runner cache"; expected = { after_script = ["finalize_nix_ci"]; before_script = ["source setup_nix_ci \"gitlab-ci:pipeline:test:job-deps:test\""]; cache = [ { key = "test"; paths = [".nix-cache/"]; } ]; variables."NIX_CI_CACHE_STRATEGY" = "runner"; }; actual = mkJobPatched { key = "test"; pipeline_name = "test"; job.nix = { enable = true; enable-runner-cache = true; runner-cache-key = "test"; }; }; } { name = "mkPipeline empty"; expected = {}; actual = (mkPipeline { name = "test"; pipeline.jobs = {}; }).finalConfig; } { name = "mkPipeline empty packages"; type = "script"; script = let pipeline = builtins.toFile "pipeline-test" (builtins.toJSON (mkPipeline { name = "test"; pipeline.jobs = {}; }).packages); in # sh '' set -euo pipefail export PATH=${lib.makeBinPath [pkgs.jq pkgs.gnugrep pkgs.coreutils]} # single key jq 'keys | length == 1' "${pipeline}" | grep -q true # key is exactly "gitlab-ci:pipeline:test" jq -r 'keys[0]' "${pipeline}" | grep -qx "gitlab-ci:pipeline:test" # value contains "/nix/store/" jq -r '.["gitlab-ci:pipeline:test"]' "${pipeline}" | grep -q "/nix/store/" # value contains "gitlab-ci-test.yml" jq -r '.["gitlab-ci:pipeline:test"]' "${pipeline}" | grep -q "gitlab-ci-test.yml" # file only contains "{}" [[ "$(cat $(jq -r '.["gitlab-ci:pipeline:test"]' "${pipeline}"))" == "{}" ]] ''; } ]; }; }