Skip to content

Commit

Permalink
fix: Make disabled tests run again (#163)
Browse files Browse the repository at this point in the history
- Enable disabled tests ⚓
- Split windows tests and disable some (todo, because they hang?) ⚓
- Remove obsolete code in test ⚓
  • Loading branch information
gabyx authored Apr 21, 2024
1 parent f4ddc7e commit 96c8671
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 79 deletions.
10 changes: 8 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ jobs:
description: "The test script name"
default: "test-alpine"
type: string
seq:
description: "The sequence of tests"
default: ""
type: string
executor:
size: medium
name: win/server-2022
version: 2023.04.1
version: 2023.11.1
steps:
- checkout
- run:
no_output_timeout: 30m
command: "& 'C:/Program Files/Git/bin/sh.exe' tests/<<parameters.test>>.sh"
command: "& 'C:/Program Files/Git/bin/bash.exe' -c 'tests/<<parameters.test>>.sh --seq <<parameters.seq>>'"

workflows:
version: 2
Expand Down Expand Up @@ -70,4 +75,5 @@ workflows:
matrix:
parameters:
test: ["test-windows"]
seq: ["{001..040}", "{041..080}", "{081..120}", "{120..200}"]
filters: *filters
26 changes: 19 additions & 7 deletions githooks/cmd/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ func defineArguments(cmd *cobra.Command, vi *viper.Viper) {
"non-interactive", false,
"Run the installation non-interactively\n"+
"without showing prompts.")
cmd.PersistentFlags().Bool(
"update", false,
"Install and update directly to the latest\n"+
"possible tag on the clone branch.")

if !cm.PackageManagerEnabled {
// Only allow this when not using a package manager.
cmd.PersistentFlags().Bool(
"update", false,
"Install and update directly to the latest\n"+
"possible tag on the clone branch.")
}

cmd.PersistentFlags().Bool(
"skip-install-into-existing", false,
"Skip installation into existing repositories\n"+
Expand Down Expand Up @@ -171,6 +176,9 @@ func defineArguments(cmd *cobra.Command, vi *viper.Viper) {
"use-pre-release", false,
"When fetching the latest installer, also consider pre-release versions.")

// The following binds all flags to `viper` config YAML over `--config`.
// So anything specified in `--config` gets transferred to the flags, that we only can use the
// variables associated in the flags.
cm.AssertNoErrorPanic(
vi.BindPFlag("config", cmd.PersistentFlags().Lookup("config")))
cm.AssertNoErrorPanic(
Expand All @@ -179,8 +187,12 @@ func defineArguments(cmd *cobra.Command, vi *viper.Viper) {
vi.BindPFlag("dryRun", cmd.PersistentFlags().Lookup("dry-run")))
cm.AssertNoErrorPanic(
vi.BindPFlag("nonInteractive", cmd.PersistentFlags().Lookup("non-interactive")))
cm.AssertNoErrorPanic(
vi.BindPFlag("update", cmd.PersistentFlags().Lookup("update")))

if !cm.PackageManagerEnabled {
cm.AssertNoErrorPanic(
vi.BindPFlag("update", cmd.PersistentFlags().Lookup("update")))
}

cm.AssertNoErrorPanic(
vi.BindPFlag("skipInstallIntoExisting", cmd.PersistentFlags().Lookup("skip-install-into-existing")))
cm.AssertNoErrorPanic(
Expand All @@ -207,6 +219,7 @@ func defineArguments(cmd *cobra.Command, vi *viper.Viper) {
vi.BindPFlag("hooksDir", cmd.PersistentFlags().Lookup("hooks-dir")))
cm.AssertNoErrorPanic(
vi.BindPFlag("hooksDirUseTemplateDir", cmd.PersistentFlags().Lookup("hooks-dir-use-template-dir")))

if !cm.PackageManagerEnabled {
cm.AssertNoErrorPanic(
vi.BindPFlag("gitConfigNoAbsPath", cmd.PersistentFlags().Lookup("git-config-no-abs-path")))
Expand Down Expand Up @@ -780,7 +793,6 @@ func setupGithooksExecutables(log cm.ILogContext, installDir string, noAbsPath b

if cm.PackageManagerEnabled || noAbsPath {
cli = hooks.GetCLIExecutable("").Cmd
log.InfoF("%v", cli)
runner = hooks.GetRunnerExecutable("")
dialog = hooks.GetDialogExecutable("")

Expand Down
2 changes: 0 additions & 2 deletions githooks/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ parse_args() {
BUILD_TAGS="$p"
elif [ "$p" = "--coverage" ]; then
BUILD_COVERAGE="true"
elif [ "$p" = "--benchmark" ]; then
DEBUG_TAG="${DEBUG_TAG}${DEBUG_TAG+,}benchmark,download_mock"
elif [ "$p" = "--prod" ]; then
DEBUG_TAG=""
LD_FLAGS+=("-ldflags" "-s -w") # strip debug information
Expand Down
15 changes: 10 additions & 5 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,6 @@ trap clean_up EXIT
githooks="$tempDir/githooks"
mkdir -p "$githooks"

cliExe="githooks-cli"
if [ "$os" = "windows" ]; then
cliExe="$cliExe.exe"
fi

cd "$tempDir"

echo -e "Downloading '$checksumFileURL'..."
Expand Down Expand Up @@ -304,6 +299,16 @@ case "$url" in
;;
esac

cliExe="cli"
if [ ! -f "githooks/cli" ]; then
# Version 3 has new names
cliExe="githooks-cli"
fi

if [ "$os" = "windows" ]; then
cliExe="$cliExe.exe"
fi

if [ "$unInstall" = "true" ]; then
"githooks/$cliExe" uninstaller "${installerArgs[@]}"
else
Expand Down
2 changes: 2 additions & 0 deletions tests/exec-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ FROM githooks:$IMAGE_TYPE-base
ARG DOCKER_GROUP_ID
ENV DOCKER_RUNNING=true
ENV GH_SCRIPTS="/var/lib/githooks-scripts"
ENV GH_TESTS="/var/lib/githooks-tests"
ENV GH_TEST_TMP="/tmp/githooks"
ENV GH_TEST_REPO="/var/lib/githooks"
Expand All @@ -63,6 +64,7 @@ RUN bash "\$GH_TESTS/setup-githooks.sh"
# Add all tests
ADD tests "\$GH_TESTS"
ADD scripts "\$GH_SCRIPTS"
# Git-Core folder must be existing.
RUN [ -d "\$GH_TEST_GIT_CORE/templates/hooks" ]
Expand Down
2 changes: 1 addition & 1 deletion tests/general.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function check_paths_are_equal() {
local a
a=$(echo "$1" | wrap_windows_paths)
local b
b=$(echo "$1" | wrap_windows_paths)
b=$(echo "$2" | wrap_windows_paths)
shift 2

[ "$a" = "$b" ] || {
Expand Down
30 changes: 23 additions & 7 deletions tests/setup-githooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,36 @@ echo "Make test Git repo to clone from ..." &&
git add . >/dev/null 2>&1 &&
git commit -a -m "Before build" >/dev/null 2>&1 || exit 1

# Make a build which exists on the server on branch "test-download"
# Make a build which exists on the server on branch test-download.
cd "$GH_TEST_REPO/githooks" &&
git checkout -b "test-download" &&
git commit -a --allow-empty \
-m "Build version 2.1.0 for download test over Github" >/dev/null 2>&1 &&
git tag "v2.1.0" &&
-m "Build version 3.0.0 for download test over Github" >/dev/null 2>&1 &&
git tag "v3.0.0" &&
./scripts/clean.sh &&
./scripts/build.sh "${BUILD_ADD_ARGS[@]}" --prod --benchmark &&
./scripts/build.sh "${BUILD_ADD_ARGS[@]}" --prod &&
./bin/githooks-cli "${CLI_ADD_ARGS[@]}" --version || exit 1
echo "Commit build v2.1.0 to repo (for test download) ..." &&
echo "Commit build v3.0.0 to repo (for test download) ..." &&
cd "$GH_TEST_REPO" &&
git add . >/dev/null 2>&1 &&
git commit -a --allow-empty -m "Version 2.1.0" >/dev/null 2>&1 &&
git tag -f "v2.1.0" || exit 1
git commit -a --allow-empty -m "Version 3.0.0" >/dev/null 2>&1 &&
git tag -f "v3.0.0" || exit 1

# Make a build is production,
# has no direct update capability in installer
# Should not download the binary
cd "$GH_TEST_REPO/githooks" &&
git checkout -b "test-package-manager" &&
git commit -a --allow-empty \
-m "Build version 3.1.0 for benchmark/package-manager test" >/dev/null 2>&1 &&
git tag "v3.1.0" &&
./scripts/clean.sh &&
./scripts/build.sh "${BUILD_ADD_ARGS[@]}" --prod --build-tags "package_manager_enabled,download_mock,benchmark" &&
echo "Commit build v3.1.0 to repo (for benchmark/package-manager test) ..." &&
cd "$GH_TEST_REPO" &&
git add . >/dev/null 2>&1 &&
git commit -a --allow-empty -m "Version 3.1.0" >/dev/null 2>&1 &&
git tag -f "v3.1.0" || exit 1

# Setup server repository from which we install updates
# branch: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ TEST_DIR=$(cd "$(dirname "$0")/.." && pwd)

init_step

git -C "$GH_TEST_REPO" reset --hard v2.1.0 >/dev/null 2>&1 || exit 1
git -C "$GH_TEST_REPO" reset --hard v3.0.0 >/dev/null 2>&1 || exit 1

# We do not want to inject special flags into the downloaded executable because it has not been build with coverage
# therefore -> use `GH_DEPLOY_SOURCE_IS_PROD` in `executables-coverage.go`
GH_DEPLOY_SOURCE_IS_PROD=true \
"$GH_TEST_BIN/githooks-cli" installer --clone-url "https://github.com/gabyx/Githooks.git" --clone-branch "main" ||
"$GH_TEST_BIN/githooks-cli" installer \
--clone-url "https://github.com/gabyx/Githooks.git" \
--clone-branch "main" \
exit 1

"$GH_INSTALL_BIN_DIR/githooks-cli" uninstaller
Expand Down
43 changes: 0 additions & 43 deletions tests/steps/disabled-step-137.sh

This file was deleted.

36 changes: 36 additions & 0 deletions tests/steps/step-137.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Test:
# Run install.sh script.
# shellcheck disable=SC2015

set -u

TEST_DIR=$(cd "$(dirname "$0")/.." && pwd)
# shellcheck disable=SC1091

. "$TEST_DIR/general.sh"

init_step

if [ -n "${GH_COVERAGE_DIR:-}" ]; then
echo "Test cannot run for coverage."
exit 249
fi

# Install with current script the version 2.10.0 on the `main` branch.
"$GH_SCRIPTS/install.sh" --version 2.10.0 || {
echo "Could not download install.sh from 'main' and install."
exit 1
}

# Enable this once pre-release is out on main.
# # Update to version 3 and greater, which should fail due to guard.
# OUT=$("$GH_INSTALL_BIN_DIR/cli" update --use-pre-release --yes)
# # shellcheck disable=SC2181
# if [ $? -eq 0 ] || ! echo "$OUT" | grep -iE "Too much changed. Please uninstall this version"; then
# echo "Install should fail because update from v2 to v3 is guarded."
# exit 1
# fi

# Uninstall right away again.
"$GH_INSTALL_BIN_DIR"/cli uninstaller || exit 1
68 changes: 68 additions & 0 deletions tests/steps/step-147.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash
# Test:
# Test package-manager enabled build with run-wrappers not using githooks.runner

TEST_DIR=$(cd "$(dirname "$0")/.." && pwd)
# shellcheck disable=SC1091
. "$TEST_DIR/general.sh"

if [ -n "$GH_ON_WINDOWS" ]; then
echo "On windows somehow this test gets stuck (?)."
exit 249
fi

init_step

# Use the 3.1.0 prod build with package-manager enabled and download mocked.
git -C "$GH_TEST_REPO" reset --hard v3.1.0 >/dev/null 2>&1 || exit 1

# run the default install
"$GH_TEST_BIN/githooks-cli" installer \
"${EXTRA_INSTALL_ARGS[@]}" \
--clone-url "file://$GH_TEST_REPO" \
--clone-branch "test-package-manager" || exit 1

# Test run-wrappers with pure binaries in the path.
# Put binaries into the path to find them.
export PATH="$GH_TEST_BIN:$PATH"
if [ -z "$GH_COVERAGE_DIR" ]; then
# Coverage build will not run this because its wrapped...
githooks-cli --version || {
echo "! Binaries not in path."
exit 1
}
fi

# Overwrite runner, it should not be needed.
git config --global --unset githooks.runner

# We need this CLI at the right place for further tests.
[ ! -f ~/.githooks/bin/githooks-cli ] || {
echo "! githooks-cli should not exist in default location"
exit 1
}
# Install it into the default location for the test functions...
mkdir ~/.githooks/bin &&
cp "$(which githooks-cli)" ~/.githooks/bin/ || exit 1

# Test the the runner works.
mkdir -p "$GH_TEST_TMP/test147" &&
cd "$GH_TEST_TMP/test147" &&
mkdir -p .githooks/pre-commit &&
echo "echo 'Hook-1' >> '$GH_TEST_TMP/test'" >.githooks/pre-commit/test1 &&
git init &&
install_hooks_if_not_centralized || exit 1

if ! is_centralized_tests; then
check_local_install
else
check_centralized_install
fi

git hooks trust
git commit --allow-empty -m "Test hook" || exit 1

if [ ! -f "$GH_TEST_TMP/test" ]; then
echo "! Hook did not run."
exit 1
fi
Loading

0 comments on commit 96c8671

Please sign in to comment.