Author: sandervanderburg
Date: Wed Feb 23 23:03:25 2011
New Revision: 26085
URL: https://svn.nixos.org/websvn/nix/?rev=26085&sc=1
Log:
Added testcases for mapStatefulToPrevious and filterBuildable
Added:
disnix/dydisnix/trunk/tests/pkgs/testService1B.nix
disnix/dydisnix/trunk/tests/qos/qos-firsttargets.nix
disnix/dydisnix/trunk/tests/qos/qos-mapstatefultoprevious.nix
disnix/dydisnix/trunk/tests/services-error.nix
Modified:
disnix/dydisnix/trunk/data/try-build.nix.in
disnix/dydisnix/trunk/release.nix
disnix/dydisnix/trunk/tests/pkgs/default.nix
Modified: disnix/dydisnix/trunk/data/try-build.nix.in
==============================================================================
--- disnix/dydisnix/trunk/data/try-build.nix.in Wed Feb 23 21:24:37 2011
(r26084)
+++ disnix/dydisnix/trunk/data/try-build.nix.in Wed Feb 23 23:03:25 2011
(r26085)
@@ -1,4 +1,6 @@
-{servicesFile, infrastructureFile, distributionFile, serviceName, targetName}:
+{ servicesFile, infrastructureFile, distributionFile, serviceName, targetName
+, nixpkgs ? builtins.getEnv "NIXPKGS_ALL"
+}:
let
inherit (builtins) getAttr;
@@ -7,15 +9,16 @@
infrastructure = import infrastructureFile;
distributionFun = import distributionFile;
- lib = import @DISNIX_PREFIX@/share/disnix/lib.nix;
+ lib = import @DISNIX_PREFIX@/share/disnix/lib.nix { inherit nixpkgs pkgs; };
+ pkgs = lib.selectPkgs system;
- services = servicesFun { system = builtins.currentSystem; distribution =
null; pkgs = null; };
distribution = distributionFun { inherit infrastructure; };
+ services = servicesFun { inherit distribution system pkgs; };
servicesWithTargets = lib.augmentTargetsInDependsOn distribution services;
target = getAttr targetName infrastructure;
system = if target ? system then target.system else builtins.currentSystem;
- pkgs = lib.selectPkgs system;
- service = getAttr serviceName (servicesFun { inherit distribution system
pkgs; });
+
+ service = getAttr serviceName servicesWithTargets;
in
if service ? dependsOn && service.dependsOn != {} then service.pkg
(service.dependsOn) else service.pkg
Modified: disnix/dydisnix/trunk/release.nix
==============================================================================
--- disnix/dydisnix/trunk/release.nix Wed Feb 23 21:24:37 2011 (r26084)
+++ disnix/dydisnix/trunk/release.nix Wed Feb 23 23:03:25 2011 (r26085)
@@ -57,6 +57,62 @@
};
};
testScript = ''
+ # Execute filter buildable. In this situation no build exceptions
+ # occur, so all machines in the network are valid candidate hosts.
+ # This test should succeed.
+
+ my $result =
$machine->mustSucceed("NIXPKGS_ALL=${nixpkgs}/pkgs/top-level/all-packages.nix
dydisnix-gendist --filter-buildable -s ${tests}/services.nix -i
${tests}/infrastructure.nix");
+ my @distribution = split('\n', $machine->mustSucceed("cat
$result"));
+
+ if(@distribution[7] =~ /testtarget1/) {
+ print "line 7 contains testtarget1!\n";
+ } else {
+ die "line 7 should contain testtarget1!\n";
+ }
+
+ if(@distribution[8] =~ /testtarget2/) {
+ print "line 8 contains testtarget2!\n";
+ } else {
+ die "line 8 should contain testtarget2!\n";
+ }
+
+ if(@distribution[13] =~ /testtarget1/) {
+ print "line 13 contains testtarget1!\n";
+ } else {
+ die "line 13 should contain testtarget1!\n";
+ }
+
+ if(@distribution[14] =~ /testtarget2/) {
+ print "line 14 contains testtarget2!\n";
+ } else {
+ die "line 14 should contain testtarget2!\n";
+ }
+
+ if(@distribution[19] =~ /testtarget1/) {
+ print "line 19 contains testtarget1!\n";
+ } else {
+ die "line 19 should contain testtarget1!\n";
+ }
+
+ if(@distribution[20] =~ /testtarget2/) {
+ print "line 20 contains testtarget2!\n";
+ } else {
+ die "line 20 should contain testtarget2!\n";
+ }
+
+ # Execute filter buildable. In this situation a build exception is
+ # thrown for testService1B rendering it undeployable.
+ # This test should succeed.
+
+ my $result =
$machine->mustSucceed("NIXPKGS_ALL=${nixpkgs}/pkgs/top-level/all-packages.nix
dydisnix-gendist --filter-buildable -s ${tests}/services-error.nix -i
${tests}/infrastructure.nix");
+ my @distribution = split('\n', $machine->mustSucceed("cat
$result"));
+
+ if(@distribution[7] =~ /testtarget1/) {
+ die "line 7 contains testtarget1!\n";
+ } else {
+ print "line 7 should contain testtarget1!\n";
+ }
+
# Execute the mapAttrOnAttr method to map requireZone onto zone.
# testService1 should be assigned to testtarget1. testService2 and
# testService3 should be assigned to testtarget2. This test should
Modified: disnix/dydisnix/trunk/tests/pkgs/default.nix
==============================================================================
--- disnix/dydisnix/trunk/tests/pkgs/default.nix Wed Feb 23 21:24:37
2011 (r26084)
+++ disnix/dydisnix/trunk/tests/pkgs/default.nix Wed Feb 23 23:03:25
2011 (r26085)
@@ -4,6 +4,10 @@
testService1 = import ./testService1.nix {
inherit (pkgs) stdenv;
};
+
+ testService1B = import ./testService1B.nix {
+ inherit (pkgs) stdenv;
+ };
testService2 = import ./testService2.nix {
inherit (pkgs) stdenv;
Added: disnix/dydisnix/trunk/tests/pkgs/testService1B.nix
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/dydisnix/trunk/tests/pkgs/testService1B.nix Wed Feb 23 23:03:25
2011 (r26085)
@@ -0,0 +1,11 @@
+{stdenv}:
+
+assert "foo" == "bar";
+
+stdenv.mkDerivation {
+ name = "testService1B";
+
+ buildCommand = ''
+ echo "testService1B" > $out
+ '';
+}
Added: disnix/dydisnix/trunk/tests/qos/qos-firsttargets.nix
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/dydisnix/trunk/tests/qos/qos-firsttargets.nix Wed Feb 23
23:03:25 2011 (r26085)
@@ -0,0 +1,9 @@
+{services, infrastructure, initialDistribution, previousDistribution, filters}:
+
+builtins.listToAttrs (map (serviceName:
+ let targets = builtins.getAttr serviceName initialDistribution;
+ in
+ { name = serviceName;
+ value = [ (builtins.head targets) ];
+ }
+) (builtins.attrNames initialDistribution))
Added: disnix/dydisnix/trunk/tests/qos/qos-mapstatefultoprevious.nix
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/dydisnix/trunk/tests/qos/qos-mapstatefultoprevious.nix Wed Feb
23 23:03:25 2011 (r26085)
@@ -0,0 +1,6 @@
+{services, infrastructure, initialDistribution, previousDistribution, filters}:
+
+filters.mapStatefulToPrevious {
+ inherit services previousDistribution;
+ distribution = initialDistribution;
+}
Added: disnix/dydisnix/trunk/tests/services-error.nix
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/dydisnix/trunk/tests/services-error.nix Wed Feb 23 23:03:25
2011 (r26085)
@@ -0,0 +1,44 @@
+{distribution, system, pkgs}:
+
+let
+ customPkgs = import ./pkgs { inherit pkgs system; };
+in
+rec {
+ testService1B = {
+ name = "testService1B";
+ pkg = customPkgs.testService1B;
+ type = "echo";
+ requireZone = "US";
+ requireZones = [ "US" "Asia" ];
+ requireMem = 262144;
+ requireAccess = [ "public" "private" ];
+ stateful = true;
+ };
+
+ testService2 = {
+ name = "testService2";
+ pkg = customPkgs.testService2;
+ dependsOn = {
+ testService1 = testService1B;
+ };
+ type = "echo";
+ requireZone = "US";
+ requireZones = [ "Europe" "Asia" ];
+ requireMem = 262143;
+ requireAccess = [ "public" "private" ];
+ };
+
+ testService3 = {
+ name = "testService3";
+ pkg = customPkgs.testService3;
+ dependsOn = {
+ testService1 = testService1B;
+ inherit testService2;
+ };
+ type = "echo";
+ requireZone = "Europe";
+ requireZones = [ "US" "Europe" ];
+ requireMem = 262145;
+ requireAccess = [ "private" ];
+ };
+}
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits