Skip to content

Commit b860feb

Browse files
authored
Merge pull request kubernetes#126540 from skitt/avoid-double-mock-headers
Handle all mock header generation with mockery
2 parents 29f96c3 + f4ddb44 commit b860feb

File tree

4 files changed

+0
-107
lines changed

4 files changed

+0
-107
lines changed

hack/update-mocks.sh

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ cd "${KUBE_ROOT}"
4444

4545
GENERATED_MOCK_FILE_REGEX="^// Code generated by mockery v[0-9.]\+. DO NOT EDIT.$"
4646

47-
# pick a tempfile path for writing to
48-
tmp=$(mktemp)
49-
kube::util::trap_add "rm -f ${tmp:?}" EXIT
50-
5147
git_grep -l -z "${GENERATED_MOCK_FILE_REGEX}" | xargs -0 rm -f
5248

5349
echo 'executing go generate command on below files'
@@ -73,58 +69,3 @@ git_grep -l -z "//go:generate mockery" | while read -r -d $'\0' file; do
7369
go -C "$(dirname "$file")" generate "$(basename "$file")"
7470
fi
7571
done
76-
77-
# get the changed or new mock files
78-
git ls-files -mo --exclude-standard -z | while read -r -d $'\0' file; do
79-
# only process files that appear to be mocks
80-
test -f "$file" || continue
81-
grep -q "${GENERATED_MOCK_FILE_REGEX}" "$file" || continue
82-
83-
# search for build tags used in file
84-
# //go:build !providerless
85-
# // +build !providerless
86-
go_build_tag_string=$(grep -o 'go:build.*$' "$file") || true
87-
build_tag_string=$(grep -o '+build.*$' "$file") || true
88-
new_header=''
89-
90-
# if the file has both headers
91-
if [ -n "$build_tag_string" ] && [ -n "$go_build_tag_string" ]
92-
then
93-
# create a new header with the build string and the copyright text
94-
new_header=$(echo -e "//""$go_build_tag_string""\n""//" "$build_tag_string""\n" | cat - hack/boilerplate/boilerplate.generatego.txt)
95-
96-
# ignore the first line (build tag) from the file
97-
tail -n +3 "$file" >"${tmp}"
98-
fi
99-
100-
# if the file has only // +build !providerless header
101-
if [ -n "$build_tag_string" ] && [ -z "$go_build_tag_string" ]
102-
then
103-
# create a new header with the build string and the copyright text
104-
new_header=$(echo -e "//" "$build_tag_string""\n" | cat - hack/boilerplate/boilerplate.generatego.txt)
105-
106-
# ignore the first line (build tag) from the file
107-
tail -n +2 "$file" >"${tmp}"
108-
fi
109-
110-
# if the file has only //go:build !providerless header
111-
if [ -z "$build_tag_string" ] && [ -n "$go_build_tag_string" ]
112-
then
113-
# create a new header with the build string and the copyright text
114-
new_header=$(echo -e "//""$go_build_tag_string""\n" | cat - hack/boilerplate/boilerplate.generatego.txt)
115-
116-
# ignore the first line (build tag) from the file
117-
tail -n +2 "$file" >"${tmp}"
118-
fi
119-
120-
# if the header is generated
121-
if [ -n "$new_header" ]
122-
then
123-
# write the newly generated header file to the original file
124-
echo -e "$new_header" | cat - "${tmp}" > "$file"
125-
else
126-
# if no build string insert at the top
127-
cat hack/boilerplate/boilerplate.generatego.txt "$file" >"${tmp}" && \
128-
mv "${tmp}" "$file"
129-
fi
130-
done

pkg/kubelet/container/testing/runtime_mock.go

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/utils/oidc/handlers/mock_jwks_handler.go

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/utils/oidc/handlers/mock_token_handler.go

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)