Skip to content

Commit

Permalink
Merge pull request #3 from Janik-Haag/develop
Browse files Browse the repository at this point in the history
intialize tests
  • Loading branch information
Janik-Haag committed Feb 15, 2024
2 parents 5ab2ddf + 51e02ca commit 4636f2b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
- name: "Check evaluation"
run: nix flake check --all-systems

# - name: "Run unit-tests"
# run: nix run github:nix-community/nix-unit -- --flake .#tests
- name: "Run unit-tests"
run: nix run github:nix-community/nix-unit -- --flake .#tests

- name: "Do linting"
run: nix run nixpkgs#statix -- check .
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
system:
nixpkgs.legacyPackages.${system}.nixpkgs-fmt
);
tests = nixpkgs.lib.mapAttrs (name: v: import "${./utils}/tests/${name}.nix" { inherit self; inherit (nixpkgs) lib; inherit (self) utils; }) (builtins.removeAttrs self.utils [ "__unfix__" "extend" "generate" ]);
devShells = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
Expand Down
36 changes: 17 additions & 19 deletions utils/networking.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
{ lib, ... }: {
networking = {
/*
/*
Generates inclusive portrange given a lower and a higher number
Type:
utils.networking.portrange:: Int -> Int -> [ Int ]
*/
portrange =
from:
to:
let
helper = input:
if input.counter >= 0 then
helper
{
list = [ (from + input.counter) ] ++ input.list;
counter = input.counter - 1;
} else input.list;
in
lib.throwIf (from > to) "the second input has to be larger then the first one, otherwise you have a negative range which is impossible or not a range."
helper
{ list = [ ]; counter = to - from; }
;
};
portrange =
from:
to:
let
helper = input:
if input.counter >= 0 then
helper
{
list = [ (from + input.counter) ] ++ input.list;
counter = input.counter - 1;
} else input.list;
in
lib.throwIf (from > to) "the second input has to be larger then the first one, otherwise you have a negative range which is impossible or not a range."
helper
{ list = [ ]; counter = to - from; }
;
}
7 changes: 7 additions & 0 deletions utils/tests/networking.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ self, lib, utils }:
{
testPortrange = {
expr = utils.networking.portrange 8000 8100;
expected = [ 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 ];
};
}

0 comments on commit 4636f2b

Please sign in to comment.