Patrick Kelley 8fd444092b initial
2025-05-07 15:35:15 -04:00

57 lines
1.6 KiB
Bash
Executable File

#! /usr/bin/env bash
#
# This initializer runs prior to every test. It creates a fresh copy of our
# test packages and package sources. Individual tests may tweak these further as
# needed, prior to running tests with them. The initializer also creates a zkg
# config that all tests automatically run with, via the "zkg" wrapper script in
# this directory.
cp -R $PACKAGES .
for p in packages/*; do
if [ $p = 'packages/foo' ]; then
# Use a different default branch than 'master' for testing purposes
( cd $p && git init && git checkout -b main && git add * && git commit -m 'init' )
else
( cd $p && git init && git add * && git commit -m 'init' )
fi
done
cp -R $SOURCES .
find sources -name 'zkg.index' -exec sed -i -e "s#^#$(pwd)/packages/#" {} \;
for s in sources/*; do
( cd $s && git init && git add * && git commit -m 'init' )
done
# Create a branch drop-corge in source "one" to drop corge from index
( cd sources/one &&
default_branch=$(git rev-parse --abbrev-ref HEAD) &&
git checkout -b drop-corge &&
sed -i -e '/corge/d' bob/zkg.index &&
git add ./bob/zkg.index &&
git commit -m 'Remove corge' &&
git checkout ${default_branch} )
cp -R $TEMPLATES .
for t in templates/*; do
(
cd $t && git init && git add * && git commit -m 'init'
git remote add origin https://example.com/zeek/package-template
)
done
echo "\
[sources]
one = $(pwd)/sources/one
[paths]
state_dir = $(pwd)/state
script_dir = $(pwd)/scripts
plugin_dir = $(pwd)/plugins
bin_dir = $(pwd)/bin
" >> config
type zeek-config > /dev/null 2>&1 && echo "zeek_dist = $(zeek-config --zeek_dist)" >> config || true