Skip to content
Snippets Groups Projects
Commit 1a5052f1 authored by Timo Furrer's avatar Timo Furrer :palm_tree:
Browse files

Merge branch 'gmh-add-mac-alternative-for-testing-scripts' into 'main'

bug: Add fallback for macOS version of readlink

See merge request !2206
parents 7977df50 8ecad425
No related branches found
No related tags found
1 merge request!2206bug: Add fallback for macOS version of readlink
Pipeline #1718285828 passed
......@@ -2,14 +2,24 @@
# This script generates the `api_generated.go` file, which includes one `go:generate` line for each interface.
# This is used to ensure we have a mocked setup for each interface we create in the client.
testing_pkg_dir=$(readlink -e "$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)/../testing")
case $(uname -s) in
Darwin)
READLINK_FLAG="-f"
;;
*)
READLINK_FLAG="-e"
;;
esac
testing_pkg_dir=$(readlink $READLINK_FLAG "$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)/../testing")
api_file="$testing_pkg_dir/api_generated.go"
(
echo '// This file is generate from scripts/generate_mock_api.sh'
echo 'package testing'
echo ''
) > "$api_file"
) >"$api_file"
# shellcheck disable=SC2162,SC2038
grep -E '^\s[A-Z][a-zA-Z0-9]+Interface interface {$' -- *.go | awk '{ print $1 $2 }' | while read line; do
......@@ -17,7 +27,7 @@ grep -E '^\s[A-Z][a-zA-Z0-9]+Interface interface {$' -- *.go | awk '{ print $1 $
filename=${filename%.go}
interface=$(echo "$line" | cut -d: -f2)
echo "//go:generate go run go.uber.org/mock/mockgen@v0.5.0 -typed -destination=${filename}_mock.go -package=testing gitlab.com/gitlab-org/api/client-go ${interface}" >> "$api_file"
echo "//go:generate go run go.uber.org/mock/mockgen@v0.5.0 -typed -destination=${filename}_mock.go -package=testing gitlab.com/gitlab-org/api/client-go ${interface}" >>"$api_file"
done
go fmt "$api_file"
......
#!/usr/bin/env sh
# This script generates a map keyed from the Service structs to the interfaces they implement. This is used
# to test that each of the service structs implement their interface properly, and automatically keeps the
# to test that each of the service structs implement their interface properly, and automatically keeps the
# map up to date so that contributors who implement new services don't need to do as much manual work.
root_dir=$(readlink -e "$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)/..")
case $(uname -s) in
Darwin)
READLINK_FLAG="-f"
;;
*)
READLINK_FLAG="-e"
;;
esac
root_dir=$(readlink $READLINK_FLAG "$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)/..")
api_service_map_test_file="$root_dir/gitlab_service_map_generated_test.go"
(
......@@ -12,7 +21,7 @@ api_service_map_test_file="$root_dir/gitlab_service_map_generated_test.go"
echo ''
echo 'var ('
echo ' serviceMap = map[any]any{'
) > "$api_service_map_test_file"
) >"$api_service_map_test_file"
# shellcheck disable=SC2162,SC2038
grep -E '^\s[A-Z][a-zA-Z0-9]+Service struct {' -- *.go | awk '{ print $1 $2 }' | while read line; do
......@@ -20,12 +29,12 @@ grep -E '^\s[A-Z][a-zA-Z0-9]+Service struct {' -- *.go | awk '{ print $1 $2 }' |
filename=${filename%.go}
service=$(echo "$line" | cut -d: -f2)
echo "&${service}{}: (*${service}Interface)(nil)," >> "$api_service_map_test_file"
echo "&${service}{}: (*${service}Interface)(nil)," >>"$api_service_map_test_file"
done
(
echo ' }'
echo ')'
) >> "$api_service_map_test_file"
) >>"$api_service_map_test_file"
go fmt "$api_service_map_test_file"
#!/usr/bin/env sh
testing_pkg_dir=$(readlink -e "$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)/../testing")
case $(uname -s) in
Darwin)
READLINK_FLAG="-f"
;;
*)
READLINK_FLAG="-e"
;;
esac
testing_pkg_dir=$(readlink $READLINK_FLAG "$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)/../testing")
testing_client_generated_file="$testing_pkg_dir/client_generated.go"
instantiations_file="$(mktemp)"
......@@ -15,7 +24,7 @@ grep -E '^\s[A-Z][a-zA-Z0-9]+\s+[A-Z][a-zA-Z0-9]+Interface$' -- gitlab.go | whil
echo "mock${field} := NewMock${interface}(ctrl)" >>"$instantiations_file"
echo "${field}: mock${field}," >>"$client_fields_file"
echo "Mock${field}: mock${field}," >>"$testclient_mock_fields_file"
echo "Mock${field} *Mock${interface}" >> "$testclient_mocks_file"
echo "Mock${field} *Mock${interface}" >>"$testclient_mocks_file"
done
(
......@@ -44,6 +53,6 @@ done
echo ' },'
echo ' }'
echo '}'
) > "$testing_client_generated_file"
) >"$testing_client_generated_file"
go fmt "$testing_client_generated_file"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment