1
1
mirror of https://github.com/nmattia/niv.git synced 2024-09-16 18:07:20 +03:00

Merge pull request #55 from nmattia/nm-test

Massage tests a bit
This commit is contained in:
Nicolas Mattia 2019-05-09 12:58:04 +02:00 committed by GitHub
commit 5d9e3a5f7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 84 deletions

View File

@ -1,10 +1,22 @@
{ pkgs ? import ./nix {} }:
with rec
{ files = pkgs.callPackage ./nix/files.nix {};
niv-source = files.sourceByRegex "niv" ./.
sourceByRegex = name: src: regexes:
builtins.path
{ filter = (path: type:
let
relPath = pkgs.lib.removePrefix (toString src + "/") (toString path);
accept = pkgs.lib.any (re: builtins.match re relPath != null) regexes;
in accept);
inherit name;
path = src;
};
niv-source = sourceByRegex "niv" ./.
[ "^package.yaml$"
"^app.*$"
"^app$"
"^app.*.hs$"
"^README.md$"
"^nix$"
"^nix.sources.nix$"
];
haskellPackages = pkgs.haskellPackages.override
@ -76,8 +88,8 @@ rec
expected_hash=$(${pkgs.nix}/bin/nix-hash ${niv-svg-gen})
actual_hash=$(grep -oP 'id="\K[^"]+' ${./site/niv.svg} -m 1)
echo expected $expected_hash
echo actuall $actual_hash
echo "expected $expected_hash"
echo "actual $actual_hash"
[ $expected_hash == $actual_hash ] && echo dymmy > $out || err
'';

View File

@ -1,60 +0,0 @@
{ lib
, writeText
, runCommand
}:
rec
{
# Lists all the (relative paths to the) files in the directory.
listFilesInDir = dir:
let
go = dir: dirName:
lib.lists.concatLists
(
lib.attrsets.mapAttrsToList
(path: ty:
if ty == "directory"
then
go "${dir}/${path}" "${dirName}${path}/"
else
[ "${dirName}${path}" ]
)
(builtins.readDir dir)
);
in go dir "";
# Like nixpkgs' sourceByRegex but doesn't depend on the directory name when
# computing the hash. Also doesn't require matching on the dir name to
# actually enter the dir.
sourceByRegex = name: src: regexes:
let
files = builtins.filter (x: x.keep) (map mk (listFilesInDir src));
mk = path:
let relPath = lib.removePrefix (toString src + "/") (toString path);
in
{ inherit relPath;
path = src + ("/" + path);
keep = lib.any (re: builtins.match re relPath != null) regexes;
};
files' = map (x: x.path) files;
paths' = map (x: x.relPath) files;
filesAbs = writeText "foo" (lib.concatStringsSep "\n" files');
filesRel = writeText "bar" (lib.concatStringsSep "\n" paths');
in
runCommand "source-${name}" {}
''
mkdir -p $out
paste ${filesAbs} ${filesRel} | while IFS="$(printf '\t')" read -r f1 f2
do
f="$out/$f2"
mkdir -p $(dirname $f)
echo $f1
echo $f2
echo $f
cp $f1 $f
done
'';
}

View File

@ -1,4 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="3390b63b37340da6e79414afb40bfa45" baseProfile="full" viewBox="0 0 703 523" width="703" version="1.1">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="7917f4fc7b0c4e04378feac08204f6c2" baseProfile="full" viewBox="0 0 703 523" width="703" version="1.1">
<defs>
<termtosvg:template_settings xmlns:termtosvg="https://github.com/nbedos/termtosvg">
<termtosvg:screen_geometry columns="82" rows="26"/>
@ -44,5 +44,5 @@
<circle cx="44" cy="23" r="7" class="color3"/>
<circle cx="64" cy="23" r="7" class="color2"/>
<svg id="screen" width="656" x="23" y="50" viewBox="0 0 656 442" preserveAspectRatio="xMidYMin meet">
<rect class="background" height="100%" width="100%" x="0" y="0"/><g display="none"><rect class="foreground" height="17" width="8" x="0" y="85"/><use y="85" xlink:href="#g1"/><animate attributeName="display" begin="0ms; anim_last.end" dur="1500ms" from="inline" to="inline"/></g><g display="none"><rect class="foreground" height="17" width="8" x="0" y="187"/><use y="187" xlink:href="#g1"/><animate attributeName="display" begin="1500ms; anim_last.end+1500ms" dur="1500ms" from="inline" to="inline"/></g><g display="none"><rect class="foreground" height="17" width="8" x="0" y="204"/><use y="204" xlink:href="#g1"/><animate attributeName="display" begin="3000ms; anim_last.end+3000ms" dur="1500ms" from="inline" to="inline"/></g><g display="none"><rect class="foreground" height="17" width="8" x="0" y="306"/><use y="306" xlink:href="#g1"/><animate attributeName="display" begin="4500ms; anim_last.end+4500ms" dur="1500ms" from="inline" to="inline"/></g><g display="none"><use y="0" xlink:href="#g2"/><use y="17" xlink:href="#g3"/><use y="34" xlink:href="#g4"/><use y="51" xlink:href="#g5"/><use y="68" xlink:href="#g6"/><animate attributeName="display" begin="0ms; anim_last.end" dur="7000ms" from="inline" to="inline"/></g><g display="none"><use y="85" xlink:href="#g7"/><use y="102" xlink:href="#g8"/><use y="119" xlink:href="#g9"/><use y="136" xlink:href="#g10"/><use y="153" xlink:href="#g11"/><use y="170" xlink:href="#g6"/><animate attributeName="display" begin="1500ms; anim_last.end+1500ms" dur="5500ms" from="inline" to="inline"/></g><g display="none"><use y="187" xlink:href="#g7"/><animate attributeName="display" begin="3000ms; anim_last.end+3000ms" dur="4000ms" from="inline" to="inline"/></g><g display="none"><use y="272" xlink:href="#g12"/><use y="289" xlink:href="#g6"/><use y="204" xlink:href="#g13"/><use y="221" xlink:href="#g14"/><use y="238" xlink:href="#g10"/><animate attributeName="display" begin="4500ms; anim_last.end+4500ms" dur="2500ms" from="inline" to="inline"/></g><g display="none"><use y="306" xlink:href="#g7"/><use y="323" xlink:href="#g15"/><use y="340" xlink:href="#g16"/><use y="357" xlink:href="#g10"/><rect class="foreground" height="17" width="8" x="0" y="374"/><use y="374" xlink:href="#g1"/><animate attributeName="display" begin="6000ms; anim_last.end+6000ms" dur="1000ms" from="inline" to="inline" id="anim_last"/></g><defs><g id="g1"><text class="background" textLength="8" x="0"> </text></g><g id="g2"><text class="foreground" textLength="80" x="0">$ niv init</text></g><g id="g3"><text class="foreground" textLength="192" x="0">Creating nix/sources.nix</text></g><g id="g4"><text class="foreground" textLength="200" x="0">Creating nix/sources.json</text></g><g id="g5"><text class="foreground" textLength="152" x="0">Importing 'niv' ...</text></g><g id="g6"><text class="foreground" textLength="160" x="0">Reading sources file</text></g><g id="g7"><text class="foreground" textLength="96" x="0">unpacking...</text></g><g id="g8"><text class="foreground" textLength="656" x="0">path is '/nix/store/pj0kr4086wciqn2kwl31sjkbnn8nm2s0-9ef6a381fc157f249f543f1c906c9</text></g><g id="g9"><text class="foreground" textLength="152" x="0">3eb12d1a3a0.tar.gz'</text></g><g id="g10"><text class="foreground" textLength="192" x="0">Writing new sources file</text></g><g id="g11"><text class="foreground" textLength="184" x="0">Importing 'nixpkgs' ...</text></g><g id="g12"><text class="foreground" textLength="168" x="0">$ niv add stedolan/jq</text></g><g id="g13"><text class="foreground" textLength="656" x="0">path is '/nix/store/v7kg3bb5qw70i2p689jz85l4kwrb11lf-571b40d3f50466d3e91c1e609d372</text></g><g id="g14"><text class="foreground" textLength="152" x="0">de96d782793.tar.gz'</text></g><g id="g15"><text class="foreground" textLength="656" x="0">path is '/nix/store/yjz2v8kfk2jkzc0w7lh43hfmcafpqs33-ad9fc9f559e78a764aac20f669f23</text></g><g id="g16"><text class="foreground" textLength="152" x="0">cdd020cd943.tar.gz'</text></g></defs></svg>
<rect class="background" height="100%" width="100%" x="0" y="0"/><g display="none"><rect class="foreground" height="17" width="8" x="0" y="85"/><use y="85" xlink:href="#g1"/><animate attributeName="display" begin="0ms; anim_last.end" dur="1500ms" from="inline" to="inline"/></g><g display="none"><rect class="foreground" height="17" width="8" x="0" y="187"/><use y="187" xlink:href="#g1"/><animate attributeName="display" begin="1500ms; anim_last.end+1500ms" dur="1500ms" from="inline" to="inline"/></g><g display="none"><rect class="foreground" height="17" width="8" x="0" y="204"/><use y="204" xlink:href="#g1"/><animate attributeName="display" begin="3000ms; anim_last.end+3000ms" dur="1500ms" from="inline" to="inline"/></g><g display="none"><rect class="foreground" height="17" width="8" x="0" y="306"/><use y="306" xlink:href="#g1"/><animate attributeName="display" begin="4500ms; anim_last.end+4500ms" dur="1500ms" from="inline" to="inline"/></g><g display="none"><use y="0" xlink:href="#g2"/><use y="17" xlink:href="#g3"/><use y="34" xlink:href="#g4"/><use y="51" xlink:href="#g5"/><use y="68" xlink:href="#g6"/><animate attributeName="display" begin="0ms; anim_last.end" dur="7000ms" from="inline" to="inline"/></g><g display="none"><use y="85" xlink:href="#g7"/><use y="102" xlink:href="#g8"/><use y="119" xlink:href="#g9"/><use y="136" xlink:href="#g10"/><use y="153" xlink:href="#g11"/><use y="170" xlink:href="#g6"/><animate attributeName="display" begin="1500ms; anim_last.end+1500ms" dur="5500ms" from="inline" to="inline"/></g><g display="none"><use y="187" xlink:href="#g7"/><animate attributeName="display" begin="3000ms; anim_last.end+3000ms" dur="4000ms" from="inline" to="inline"/></g><g display="none"><use y="272" xlink:href="#g12"/><use y="289" xlink:href="#g6"/><use y="204" xlink:href="#g13"/><use y="221" xlink:href="#g14"/><use y="238" xlink:href="#g10"/><animate attributeName="display" begin="4500ms; anim_last.end+4500ms" dur="2500ms" from="inline" to="inline"/></g><g display="none"><use y="306" xlink:href="#g7"/><use y="323" xlink:href="#g15"/><use y="340" xlink:href="#g16"/><use y="357" xlink:href="#g10"/><rect class="foreground" height="17" width="8" x="0" y="374"/><use y="374" xlink:href="#g1"/><animate attributeName="display" begin="6000ms; anim_last.end+6000ms" dur="1000ms" from="inline" to="inline" id="anim_last"/></g><defs><g id="g1"><text class="background" textLength="8" x="0"> </text></g><g id="g2"><text class="foreground" textLength="80" x="0">$ niv init</text></g><g id="g3"><text class="foreground" textLength="192" x="0">Creating nix/sources.nix</text></g><g id="g4"><text class="foreground" textLength="200" x="0">Creating nix/sources.json</text></g><g id="g5"><text class="foreground" textLength="152" x="0">Importing 'niv' ...</text></g><g id="g6"><text class="foreground" textLength="160" x="0">Reading sources file</text></g><g id="g7"><text class="foreground" textLength="96" x="0">unpacking...</text></g><g id="g8"><text class="foreground" textLength="656" x="0">path is '/nix/store/xrvnfamz6i3dv28c6fv3ylga280zdhwy-e5e441998ede88dfce5b8b9a7ea99</text></g><g id="g9"><text class="foreground" textLength="152" x="0">e1e0f1102fa.tar.gz'</text></g><g id="g10"><text class="foreground" textLength="192" x="0">Writing new sources file</text></g><g id="g11"><text class="foreground" textLength="184" x="0">Importing 'nixpkgs' ...</text></g><g id="g12"><text class="foreground" textLength="168" x="0">$ niv add stedolan/jq</text></g><g id="g13"><text class="foreground" textLength="656" x="0">path is '/nix/store/kaighy7gkrxmrlx6qfjk6g1q8iy37n28-7413c884f052e02c7825aa93a1c16</text></g><g id="g14"><text class="foreground" textLength="152" x="0">649cc3cb29b.tar.gz'</text></g><g id="g15"><text class="foreground" textLength="656" x="0">path is '/nix/store/yjz2v8kfk2jkzc0w7lh43hfmcafpqs33-ad9fc9f559e78a764aac20f669f23</text></g><g id="g16"><text class="foreground" textLength="152" x="0">cdd020cd943.tar.gz'</text></g></defs></svg>
</svg>

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -15,6 +15,9 @@
{ pkgs, niv }:
let
niv_HEAD = "a489b65a5c3a29983701069d1ce395b23d9bde64";
niv_HEAD- = "abc51449406ba3279c466b4d356b4ae8522ceb58";
nixpkgs-channels_HEAD = "571b40d3f50466d3e91c1e609d372de96d782793";
nivForTest = niv.overrideDerivation(old: {
# TODO: Remove this patch by adding an argument to the github
# subcommand to support GitHub entreprise.
@ -23,18 +26,27 @@ let
sed "s|https://github.com|http://localhost:3333|" -i app/Niv.hs
'';
});
in pkgs.runCommand "test" { buildInputs = [ pkgs.python nivForTest pkgs.nix pkgs.jq pkgs.netcat-gnu ]; }
in pkgs.runCommand "test"
{ buildInputs =
[ pkgs.haskellPackages.wai-app-static
nivForTest
pkgs.nix
pkgs.jq
pkgs.netcat-gnu
];
}
''
set -euo pipefail
echo *** Starting the webserver...
mkdir mock
( cd mock; python -m SimpleHTTPServer 3333 ) &
mkdir -p mock
while ! nc -z 127.0.0.1 3333; do
echo waiting for mock server
sleep 1
done
warp -d mock -p 3333 &
while ! nc -z 127.0.0.1 3333; do
echo waiting for mock server
sleep 1
done
# We can't access /nix or /var from the sandbox
export NIX_STATE_DIR=$PWD/nix/var/nix
@ -42,17 +54,25 @@ in pkgs.runCommand "test" { buildInputs = [ pkgs.python nivForTest pkgs.nix pkgs
echo -e "\n*** niv init"
## mock API behavior:
## - niv points to HEAD
## - nixpkgs-channels points to HEAD
mkdir -p mock/repos/nmattia/niv/
cp ${./data/repos/nmattia/niv/repository.json} mock/repos/nmattia/niv/index.html
cat ${./data/repos/nmattia/niv/commits.json} | jq '.[0] | [.]' > mock/repos/nmattia/niv/commits
# XXX: cat so we don't inherit the read-only permissions
cat ${./data/repos/nmattia/niv/commits.json} > mock/repos/nmattia/niv/commits
mkdir -p mock/nmattia/niv/archive
cp ${./data/archives/a489b65a5c3a29983701069d1ce395b23d9bde64.tar.gz} mock/nmattia/niv/archive/a489b65a5c3a29983701069d1ce395b23d9bde64.tar.gz
cp ${./data/archives + "/${niv_HEAD}.tar.gz"} \
mock/nmattia/niv/archive/${niv_HEAD}.tar.gz
mkdir -p mock/repos/NixOS/nixpkgs-channels
cp ${./data/repos/NixOS/nixpkgs-channels/repository.json} mock/repos/NixOS/nixpkgs-channels/index.html
cat ${./data/repos/NixOS/nixpkgs-channels/commits.json} | jq '.[0] | [.]' > mock/repos/NixOS/nixpkgs-channels/commits
cat ${./data/repos/NixOS/nixpkgs-channels/commits.json} > mock/repos/NixOS/nixpkgs-channels/commits
mkdir -p mock/NixOS/nixpkgs-channels/archive
cp ${./data/archives/571b40d3f50466d3e91c1e609d372de96d782793.tar.gz} mock/NixOS/nixpkgs-channels/archive/571b40d3f50466d3e91c1e609d372de96d782793.tar.gz
cp ${./data/archives + "/${nixpkgs-channels_HEAD}.tar.gz"} \
mock/NixOS/nixpkgs-channels/archive/${nixpkgs-channels_HEAD}.tar.gz
niv init
diff -h ${./expected/niv-init.json} nix/sources.json
@ -65,25 +85,32 @@ in pkgs.runCommand "test" { buildInputs = [ pkgs.python nivForTest pkgs.nix pkgs
cat nix/sources.json | jq -e '. | has("niv") | not'
echo -e "*** ok."
## mock API behavior:
## - niv points to HEAD~
## - nixpkgs-channels points to HEAD
echo -e "\n*** niv add nmattia/niv"
# We use the HEAD~1 commit to update it in the next step
cat ${./data/repos/nmattia/niv/commits.json} | jq '.[1] | [.]' > mock/repos/nmattia/niv/commits
cp ${./data/archives/abc51449406ba3279c466b4d356b4ae8522ceb58.tar.gz} mock/nmattia/niv/archive/abc51449406ba3279c466b4d356b4ae8522ceb58.tar.gz
# (e.g. we drop the first element of the commit array)
cat ${./data/repos/nmattia/niv/commits.json} | jq 'del(.[0])' > mock/repos/nmattia/niv/commits
cp ${./data/archives + "/${niv_HEAD-}.tar.gz"} \
mock/nmattia/niv/archive/${niv_HEAD-}.tar.gz
niv add nmattia/niv
echo -n "niv.rev == abc51449406ba3279c466b4d356b4ae8522ceb58: "
cat nix/sources.json | jq -e '.niv | .rev == "abc51449406ba3279c466b4d356b4ae8522ceb58"'
echo -n "niv.rev == ${niv_HEAD-} (HEAD~): "
cat nix/sources.json | jq -e '.niv | .rev == "${niv_HEAD-}"'
echo -e "*** ok."
## mock API behavior:
## - niv points to HEAD
## - nixpkgs-channels points to HEAD
echo -e "\n*** niv update niv"
cat ${./data/repos/nmattia/niv/commits.json} | jq '.[0] | [.]' > mock/repos/nmattia/niv/commits
niv update niv
echo -n "niv.rev == a489b65a5c3a29983701069d1ce395b23d9bde64: "
cat nix/sources.json | jq -e '.niv | .rev == "a489b65a5c3a29983701069d1ce395b23d9bde64"'
echo -n "niv.rev == ${niv_HEAD} (HEAD): "
cat nix/sources.json | jq -e '.niv | .rev == "${niv_HEAD}"'
echo -e "*** ok."
echo -e "\n*** niv add foo -v 1 -t 'localhost:3333/foo-v<version>'"
echo foo > mock/foo-v1
niv add foo -v 1 -t 'localhost:3333/foo-v<version>'