Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: allow for clean-up and regenerating go files #1620

Merged
merged 10 commits into from
Jan 29, 2024

Conversation

parametalol
Copy link
Contributor

@parametalol parametalol commented Jan 25, 2024

  • Resolve circular dependencies of mocks and interfaces.
  • New clean/go-generated Makefile target.
  • New CI test for generated code.

Tested:

$ make clean/go-generated
Cleaning generated .go files...
./fleetshard/pkg/central/cloudprovider/dbclient_moq.go
./fleetshard/pkg/cipher/cipher_moq.go
./internal/dinosaur/pkg/clusters/clusterbuilder_moq.go
./internal/dinosaur/pkg/clusters/provider_moq.go
./internal/dinosaur/pkg/clusters/provider_factory_moq.go
./internal/dinosaur/pkg/services/cloud_providers_moq.go
./internal/dinosaur/pkg/services/cluster_placement_strategy_moq.go
./internal/dinosaur/pkg/services/clusterservice_moq.go
./internal/dinosaur/pkg/services/dinosaurservice_moq.go
./internal/dinosaur/pkg/services/observatorium_service_moq.go
./internal/dinosaur/pkg/services/quotaservice_moq.go
./internal/dinosaur/pkg/services/quota_service_factory_moq.go
./internal/dinosaur/pkg/services/telemetry_moq.go
./pkg/auth/auth_agent_service_moq.go
./pkg/client/aws/client_moq.go
./pkg/client/iam/client_moq.go
./pkg/client/iam/gocloak_moq.go
./pkg/client/observatorium/mocks/api_moq.go
./pkg/client/ocm/mocks/client_moq.go
./pkg/client/ocm/mocks/id_generator_moq.go
./pkg/client/fleetmanager/mocks/client_moq.go
./pkg/client/telemetry/telemeter_moq.go
./pkg/client/telemetry/config_moq.go
./pkg/services/authorization/authorization_moq.go
./pkg/services/sso/iam_service_moq.go
./pkg/workers/worker_interface_moq.go
./probe/pkg/probe/probe_moq.go
$ make generate
rm -rf internal/dinosaur/pkg/api/public
/home/mipetrov/go/src/github.com/stackrox/acs-fleet-manager/bin/openapi-generator validate -i openapi/fleet-manager.yaml
Validating spec (openapi/fleet-manager.yaml)
.
.
.
gofmt -w pkg/client/redhatsso/api
go generate ./...
$ echo $?
0

@parametalol
Copy link
Contributor Author

parametalol commented Jan 25, 2024

Current dependencies on/for this PR:

@parametalol parametalol changed the title michael/refactor-generated refactor: allow for clean-up and regenerating go files Jan 25, 2024
- name: Test generated files
run: |
make clean/go-generated && make generate
git diff --exit-code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


clean/go-generated:
@echo "Cleaning generated .go files..."
@find . -name '*.go' | xargs grep -l '// Code generated by .*; DO NOT EDIT.$$' | while read -r file; do echo ""$$file""; rm -f "$$file"; done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to although in that one we only check for mocks

Comment on lines 23 to 24
"github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager"
fmImpl "github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager/impl"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there is just one occurence of fleetmanager in this file I think we can swap this imports.

Suggested change
"github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager"
fmImpl "github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager/impl"
fm "github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager"
fleetmanager "github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager/impl"

@@ -7,6 +7,8 @@ import (
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/clusters/types"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/config"
"github.com/stackrox/acs-fleet-manager/pkg/client/ocm"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we replace interface idGenerator ocm.IDGenerator we can remove this import and keep other namped as ocm causing less changes


clustersmgmtv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
"github.com/pkg/errors"
"github.com/stackrox/acs-fleet-manager/pkg/api"
)

const (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a separated PR with enabling unused linter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@janisz janisz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we work with naming then we can keep diff smaller on the other hand it's good to have it consistent. I'd like to remove changes not related to this PR.

Copy link
Contributor

openshift-ci bot commented Jan 26, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 0x656b694d, janisz
Once this PR has been reviewed and has the lgtm label, please assign ludydoo for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@parametalol parametalol force-pushed the michael/refactor-generated branch from 80e6576 to 225f41a Compare January 26, 2024 13:13
@openshift-ci openshift-ci bot removed the lgtm label Jan 26, 2024
Copy link
Contributor

openshift-ci bot commented Jan 26, 2024

New changes are detected. LGTM label has been removed.

@parametalol
Copy link
Contributor Author

/retest

@parametalol parametalol merged commit 6bc66b7 into main Jan 29, 2024
9 checks passed
@parametalol parametalol deleted the michael/refactor-generated branch January 29, 2024 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants