Skip to content

Commit

Permalink
Merge pull request #5154 from RainbowMango/pr_fix_mockgen_imports
Browse files Browse the repository at this point in the history
Fix mockgen generated files not group imports issue
  • Loading branch information
karmada-bot authored Jul 9, 2024
2 parents ffdc58c + 82b61dc commit 625d8a5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hack/update-import-aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
cd "${SCRIPT_ROOT}"
ROOT_PATH=$(pwd)

GO111MODULE=on go install "golang.org/x/tools/cmd/goimports@v0.1.5"
GO111MODULE=on go install "golang.org/x/tools/cmd/goimports"

IMPORT_ALIASES_PATH="${ROOT_PATH}/hack/.import-aliases"
INCLUDE_PATH="(${ROOT_PATH}/cmd|${ROOT_PATH}/test/e2e|${ROOT_PATH}/test/helper|\
Expand Down
7 changes: 6 additions & 1 deletion hack/update-mocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ trap EXIT

echo 'installing mockgen'
source "${KARMADA_ROOT}"/hack/util.sh
echo -n "Preparing: 'mockgen' existence check - "
echo "Preparing: 'mockgen' existence check - "
if [ ! $(util::cmd_exist mockgen) ]; then
# install from vendor with the pinned version in go.mod file
GO111MODULE=on go install "go.uber.org/mock/mockgen"
fi
echo "Preparing: 'goimports' existence check - "
if [ ! $(util::cmd_exist goimports) ]; then
# install from vendor with the pinned version in go.mod file
GO111MODULE=on go install "golang.org/x/tools/cmd/goimports"
fi

find_files() {
find . -not \( \
Expand Down
5 changes: 5 additions & 0 deletions pkg/scheduler/framework/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Given mockgen does not group imports according to our project's conventions.
// Following the mockgen command, we run 'goimports', which reformats the
// generated file to ensure that all imports are properly grouped and sorted,
// maintaining consistency with the rest of our codebase.
//go:generate mockgen -source=interface.go -destination=testing/mock_interface.go -package=testing FilterPlugin ScorePlugin ScoreExtensions
//go:generate goimports -local "github.com/karmada-io/karmada" -w testing/mock_interface.go

package framework

Expand Down
3 changes: 2 additions & 1 deletion pkg/scheduler/framework/testing/mock_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 625d8a5

Please sign in to comment.