diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-10 09:59:33 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-10 11:40:42 +0300 |
commit | 5bcc6ef3f0c94440ad5dc9b6e2bacac63e0133db (patch) | |
tree | c489995f3ab5158759283733cb13a7d89586daf8 | |
parent | 256f96c4a2933d24c2a5924a30c6dfd8e876c4eb (diff) |
operations: Convert test hooks to use Bash instead of Ruby
As we're progressing with out conversion of Ruby-based code we're
drawing ever closer to a future where there is no Ruby in Gitaly's code
base anymore. Some of our tests still depend on Ruby though because they
use a set of custom hooks that are implemented in it.
Refactor these scripts to use Bash instead of Ruby. This requires less
boilerplate code and gets rid of the last set of custom hooks in our
tests that use Ruby.
-rw-r--r-- | internal/gitaly/service/operations/tags_test.go | 84 |
1 files changed, 36 insertions, 48 deletions
diff --git a/internal/gitaly/service/operations/tags_test.go b/internal/gitaly/service/operations/tags_test.go index c7b1f6ea7..37fa8af95 100644 --- a/internal/gitaly/service/operations/tags_test.go +++ b/internal/gitaly/service/operations/tags_test.go @@ -85,60 +85,48 @@ func TestUserDeleteTag_hooks(t *testing.T) { func writeAssertObjectTypePreReceiveHook(t *testing.T, repoPath, expectedObjectType string) { t.Helper() - gittest.WriteCustomHook(t, repoPath, "pre-receive", []byte(fmt.Sprintf( - `#!/usr/bin/env ruby - - # We match a non-ASCII ref_name below - Encoding.default_external = Encoding::UTF_8 - Encoding.default_internal = Encoding::UTF_8 - - expected_object_type = %q - commands = STDIN.each_line.map(&:chomp) - unless commands.size == 1 - abort "expected 1 ref update command, got #{commands.size}" - end - - old_value, new_value, ref_name = commands[0].split(' ', 3) - abort 'missing new_value' unless new_value - - out = IO.popen(%%W[git cat-file -t #{new_value}], &:read) - abort 'cat-file failed' unless $?.success? - - if ref_name =~ /^refs\/[^\/]+\/skip-type-check-/ - exit 0 - end - - unless out.chomp == expected_object_type - abort "pre-receive hook error: expected '#{ref_name}' update of '#{old_value}' (a) -> '#{new_value}' (b) for 'b' to be a '#{expected_object_type}' object, got '#{out}'" - end + gittest.WriteCustomHook(t, repoPath, "pre-receive", []byte(fmt.Sprintf(`#!/bin/bash + i=0 + while read oldvalue newvalue reference + do + i=$((i+1)) + + if [[ "${reference}" =~ skip-type-check- ]] + then + continue + fi + + type="$(git cat-file -t "${newvalue}")" + if test "%[1]s" != "${type}" + then + echo "expected %[1]s, got ${type}" >&2 + exit 1 + fi + done + + if test "$i" -ne 1 + then + echo "expected exactly one reference update, got ${i}" >&2 + exit 1 + fi `, expectedObjectType))) } func writeAssertObjectTypeUpdateHook(t *testing.T, repoPath, expectedObjectType string) { t.Helper() - gittest.WriteCustomHook(t, repoPath, "update", []byte(fmt.Sprintf( - `#!/usr/bin/env ruby - - # We match a non-ASCII ref_name below - Encoding.default_external = Encoding::UTF_8 - Encoding.default_internal = Encoding::UTF_8 - - expected_object_type = %q - ref_name, old_value, new_value = ARGV[0..2] - - abort "missing new_value" unless new_value - - out = IO.popen(%%W[git cat-file -t #{new_value}], &:read) - abort 'cat-file failed' unless $?.success? - - if ref_name =~ /^refs\/[^\/]+\/skip-type-check-/ - exit 0 - end - - unless out.chomp == expected_object_type - abort "update hook error: expected '#{ref_name}' update of '#{old_value}' (a) -> '#{new_value}' (b) for 'b' to be a '#{expected_object_type}' object, got '#{out}'" - end + gittest.WriteCustomHook(t, repoPath, "update", []byte(fmt.Sprintf(`#!/bin/bash + if [[ "$1" =~ skip-type-check- ]] + then + exit 0 + fi + + type="$(git cat-file -t "$3")" + if test "%[1]s" != "${type}" + then + echo "expected %[1]s, got ${type}" >&2 + exit 1 + fi `, expectedObjectType))) } |