Commit 25a5fced authored by Robert Hensing's avatar Robert Hensing Committed by github-actions[bot]
Browse files

testers.lycheeLinkCheck: Generalize remapUrl convenience feature

(cherry picked from commit f6b78913688bf7096b474923fbdad00e55b23511)
parent 8bfb6afc
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -82,6 +82,19 @@ It has two modes:

: The path to the files to check.

`remap` (attribe set, optional) {#tester-lycheeLinkCheck-param-remap}

: An attribute set where the attribute names are the URLs to remap.

  The values should be store path strings, derivations or path values.

  Before checking the existence of URLs, if it is equal to the attribute name, it is replaced by the value of the attribute.
  If it is a subpath of the attribute name, it is replaced by a subpath of the value.

  This is useful for remapping URLs that are not accessible from the build environment.

  Example: `{ "https://blog.example.com" = site; }`

`extraConfig` (attribute set) {#tester-lycheeLinkCheck-param-extraConfig}

: Extra configuration to pass to `lychee` in its [configuration file](https://github.com/lycheeverse/lychee/blob/master/lychee.example.toml).
@@ -92,6 +105,7 @@ It has two modes:
`lychee` (derivation, optional) {#tester-lycheeLinkCheck-param-lychee}

: The `lychee` package to use.

## `testVersion` {#tester-testVersion}

Checks that the output from running a command contains the specified version string in it as a whole word.
+12 −4
Original line number Diff line number Diff line
deps@{ formats, lib, lychee, stdenv, writeShellApplication }:
let
  inherit (lib) concatLists isPath mapAttrsToList;
  inherit (lib.strings) hasPrefix;

  toURL = v:
    if builtins.isString v && hasPrefix builtins.storeDir v
      || isPath v
    then "file://${v}"
    else "${v}";

  # See https://nixos.org/manual/nixpkgs/unstable/#tester-lycheeLinkCheck
  # or doc/builders/testers.chapter.md
  lycheeLinkCheck = {
    site,
    remapUrl ? null,
    remap ? { },
    lychee ? deps.lychee,
    extraConfig ? { },
  }:
@@ -17,11 +25,11 @@ let

      # These can be overriden with overrideAttrs if needed.
      passthru = {
        inherit lychee remapUrl;
        inherit lychee remap;
        config = {
          include_fragments = true;
        } // lib.optionalAttrs (finalAttrs.passthru.remapUrl != null) {
          remap = [ "${remapUrl} file://${finalAttrs.site}" ];
        } // lib.optionalAttrs (finalAttrs.passthru.remap != { }) {
          remap = mapAttrsToList (name: value: "${name} ${toURL value}") finalAttrs.passthru.remap;
        } // extraConfig;
        online = writeShellApplication {
          name = "run-lychee-online";
+2 −2
Original line number Diff line number Diff line
@@ -7,9 +7,9 @@ let
    echo "<html><body><a href=\".\">index</a></body></html>" > $dist/foo.html
  '';

  linkCheck = testers.lycheeLinkCheck {
  linkCheck = testers.lycheeLinkCheck rec {
    site = sitePkg + "/dist";
    remapUrl = "https://example.com";
    remap = { "https://example.com"= site; };
  };

  failure = testers.testBuildFailure linkCheck;
+2 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ let
    echo "<html><body><a href=\"https://example.com/foo.html\">foo</a></body></html>" > $dist/index.html
    echo "<html><body><a href=\".\">index</a></body></html>" > $dist/foo.html
  '';
in testers.lycheeLinkCheck {
in testers.lycheeLinkCheck rec {
  site = sitePkg + "/dist";
  remapUrl = "https://example.com";
  remap = { "https://example.com" = site; };
}