From dd354bc323cd3176c9676444f99b33b69d0a2062 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 14 May 2022 15:21:52 -0600 Subject: Create srv.dev-shell target in Makefile --- Makefile | 16 ++++++++++------ srv-dev-env.sh | 29 +++++++++++++++++++++++++++++ srv/default.nix | 17 ++++++----------- test.sh | 29 ----------------------------- 4 files changed, 45 insertions(+), 46 deletions(-) create mode 100644 srv-dev-env.sh delete mode 100644 test.sh diff --git a/Makefile b/Makefile index de7e4f1..f5eadc0 100644 --- a/Makefile +++ b/Makefile @@ -6,16 +6,20 @@ entrypoint: --arg baseConfig '(import ${CONFIG})' install: - nix-build -A install --arg baseConfig '(import ${CONFIG})' - ./result + $$(nix-build -A install --arg baseConfig '(import ${CONFIG})') test: - $$(nix-build --no-out-link -A pkgs.bash)/bin/bash test.sh - @if [ $$? == 0 ]; then echo "TESTS PASSED!"; else echo "TESTS FAILED!"; fi + $$(nix-build --no-out-link -A pkgs.bash)/bin/bash srv-dev-env.sh \ + --run "cd srv/src && go test ./... -count=1 -tags integration" + @echo "\nTESTS PASSED!\n" + +srv.dev-shell: + $$(nix-build --no-out-link -A pkgs.bash)/bin/bash srv-dev-env.sh \ + --command "cd srv/src; return" srv.shell: - nix-shell -A srv.shell --arg baseConfig '(import ${CONFIG})' \ - --command 'cd srv; return' + nix-shell -A srv.shellWithBuild --arg baseConfig '(import ${CONFIG})' \ + --command 'cd srv/src; return' # TODO static is on the way out, these aren't well supported static.serve: diff --git a/srv-dev-env.sh b/srv-dev-env.sh new file mode 100644 index 0000000..2df9918 --- /dev/null +++ b/srv-dev-env.sh @@ -0,0 +1,29 @@ + +test_dir="$(mktemp -d)" + +mkdir -p "$test_dir"/run +mkdir -p "$test_dir"/data + +test_cfg="(import ./config.nix) // { + runDir=\"${test_dir}/run\"; + dataDir=\"${test_dir}/data\"; +}" + +entrypoint=$(nix-build --no-out-link -A entrypoint \ + --arg baseConfig "$test_cfg" \ + --arg skipServices '["srv"]') + +$entrypoint & +trap "kill $!; wait; rm -rf $test_dir" EXIT + +# NOTE this is a bit of a hack... the location of the redis socket's source of +# truth is in default.nix, but it's not clear how to get that from there to +# here, so we reproduce the calculation here. +while [ ! -e $test_dir/run/redis ]; do + echo "waiting for redis unix socket" + sleep 1 +done + +nix-shell -A srv.shell \ + --arg baseConfig "$test_cfg" \ + "$@" diff --git a/srv/default.nix b/srv/default.nix index a5aa6af..7067e1e 100644 --- a/srv/default.nix +++ b/srv/default.nix @@ -52,18 +52,13 @@ shell = stdenv.mkDerivation { name = "mediocre-blog-srv-shell"; - buildInputs = [ go build ]; - shellHook = '' - source ${init} - cd src - ''; + buildInputs = [ go ]; + shellHook = ''source ${init}''; }; - test = stdenv.mkDerivation { - name = "mediocre-blog-srv-test"; - buildInputs = [ go ]; - shellHook = '' - source ${init} - ''; + shellWithBuild = stdenv.mkDerivation { + name = "mediocre-blog-srv-shell-with-build"; + buildInputs = [ go build ]; + shellHook = ''source ${init}''; }; } diff --git a/test.sh b/test.sh deleted file mode 100644 index b45cd55..0000000 --- a/test.sh +++ /dev/null @@ -1,29 +0,0 @@ - -test_dir="$(mktemp -d)" - -mkdir -p "$test_dir"/run -mkdir -p "$test_dir"/data - -test_cfg="(import ./config.nix) // { - runDir=\"${test_dir}/run\"; - dataDir=\"${test_dir}/data\"; -}" - -entrypoint=$(nix-build --no-out-link -A entrypoint \ - --arg baseConfig "$test_cfg" \ - --arg skipServices '["srv"]') - -$entrypoint & -trap "kill $!; wait; rm -rf $test_dir" EXIT - -# NOTE this is a bit of a hack... the location of the redis socket's source of -# truth is in default.nix, but it's not clear how to get that from there to -# here, so we reproduce the calculation here. -while [ ! -e $test_dir/run/redis ]; do - echo "waiting for redis unix socket" - sleep 1 -done - -nix-shell -A srv.test \ - --arg baseConfig "$test_cfg" \ - --run "cd srv/src && go test ./... -count=1 -tags integration" -- cgit v1.2.3