Skip to content

Commit

Permalink
Merge pull request #628 from socallinuxexpo/rh/1696709124gomplate
Browse files Browse the repository at this point in the history
[READY] - golden-tests: migrate to nix check
  • Loading branch information
owendelong authored Oct 18, 2023
2 parents 4699e5e + 5526839 commit e857c20
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 42 deletions.
37 changes: 0 additions & 37 deletions .github/workflows/openwrt-golden.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/validate-datafiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: nix build -L .#checks.x86_64-linux.pytest-facts
- run: nix build -L .#checks.x86_64-linux.perl-switches
- run: nix build -L .#checks.x86_64-linux.openwrt-golden
10 changes: 10 additions & 0 deletions nix/tests/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
make .build-switch-configs
touch $out
'');
openwrt-golden = pkgs.runCommand "openwrt-golden"
{
buildInputs = [ pkgs.diffutils pkgs.gomplate ];
} ''
cp -r --no-preserve=mode ${pkgs.lib.cleanSource inputs.self}/* .
cd tests/unit/openwrt
mkdir -p $out/tmp/ar71xx
${pkgs.bash}/bin/bash test.sh -t ar71xx -o $out
'';

};
};
}
14 changes: 9 additions & 5 deletions tests/unit/openwrt/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Simple test for gomplate generated templates
OPTIONS:
-h Show this message
-o specify output for temporary generated templates
-t Target arch to build
-u Update golden templates
Expand All @@ -17,7 +18,7 @@ EXAMPLES:
EOF
}

while getopts "ht:u" OPTION
while getopts "ho:t:u" OPTION
do
case $OPTION in
u )
Expand All @@ -26,6 +27,9 @@ do
t )
TARGET=$OPTARG
;;
o )
OUTPUT=$OPTARG
;;
h )
usage
exit 0
Expand All @@ -41,16 +45,16 @@ shift $((OPTIND -1))
TARGET=${TARGET:-'ar71xx'}
UPDATE=${UPDATE:-0}

TMPLOC="tmp/${TARGET}"
TMPLOC="${OUTPUT:-.}/tmp/${TARGET}"
KEYPATH="../../../facts/keys/"

gen_templates(){
# Export to support ENV datasource
export TARGET=$TARGET
export KEYPATH=$KEYPATH
gomplate -d openwrt=../../../facts/secrets/${TARGET}-openwrt-example.yaml -d keys_dir=${KEYPATH} --input-dir=../../../openwrt/files --output-dir="./${1}"
gomplate -d openwrt=../../../facts/secrets/${TARGET}-openwrt-example.yaml -d keys_dir=${KEYPATH} --input-dir=../../../openwrt/files --output-dir="${1}"
if [ -d ../../../openwrt/files-${TARGET} ]; then
gomplate -d openwrt=../../../facts/secrets/${TARGET}-openwrt-example.yaml -d keys_dir=${KEYPATH} --input-dir=../../../openwrt/files-${TARGET} --output-dir="./${1}"
gomplate -d openwrt=../../../facts/secrets/${TARGET}-openwrt-example.yaml -d keys_dir=${KEYPATH} --input-dir=../../../openwrt/files-${TARGET} --output-dir="${1}"
fi
}

Expand All @@ -59,6 +63,6 @@ if [ ${UPDATE} -eq 1 ]; then
gen_templates "golden/${TARGET}"
fi

gen_templates $TMPLOC
gen_templates "$TMPLOC"

diff -u -r "golden/${TARGET}" $TMPLOC/

0 comments on commit e857c20

Please sign in to comment.