Skip to content

Clean-up after PR 3509 #3517

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

Merged
merged 6 commits into from
Mar 21, 2025
Merged

Clean-up after PR 3509 #3517

merged 6 commits into from
Mar 21, 2025

Conversation

ramondeklein
Copy link
Collaborator

@ramondeklein ramondeklein commented Mar 13, 2025

This PR implements the following changes:

I was cleaning up the redundant code in upstream console and I noticed it was full of global variables for mocking. Global variables should be avoided and especially in Go unit tests, because tests may run in parallel when you run go test ./.... Unless t.Parallel() is called, tests within a single package run sequentially. But Go does run multiple packages in parallel, so it may be tricky when the mocked type is used in multiple packages.

It's often easy to convert the globals to fields inside the struct, so I would propose to avoid global variables unless it's unavoidable. Made the change in console in this commit. Test code should mostly follow the same coding practices as normal code. We shouldn't be sloppy, because it's "just" test code.

PS: The mocking types were private, so I won't expect problems with the previous implementation. But it's often that a private type is made public later, so I rather keep code safe.

@ramondeklein ramondeklein requested a review from bexsoft March 13, 2025 10:06
@ramondeklein ramondeklein self-assigned this Mar 13, 2025
@ramondeklein ramondeklein changed the title Remove unused code Clean-up after PR 3509 Mar 13, 2025
@ramondeklein ramondeklein force-pushed the cleanup branch 2 times, most recently from da8b81b to 0a6a9a1 Compare March 13, 2025 11:28
@ramondeklein
Copy link
Collaborator Author

ramondeklein commented Mar 13, 2025

I tried to upgrade @babel/runtime to v7.26.10, but wasn't successful. @bexsoft Can you take a look?

Found it...

@ramondeklein ramondeklein marked this pull request as draft March 13, 2025 11:31
@ramondeklein ramondeklein marked this pull request as ready for review March 13, 2025 11:39
Copy link
Collaborator

@cesnietor cesnietor left a comment

Choose a reason for hiding this comment

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

LGTM just saw a test failing. plus some linting :

type `wsAdminClient` is unused (unused)
func `sendWsCloseMessage` is unused (unused)

@ramondeklein
Copy link
Collaborator Author

ramondeklein commented Mar 13, 2025

@cesnietor These linter issues have already been fixed in commit 0a6a9a1. Not sure why you are still seeing them.

Fixed Test_enableBucketEncryption in 8ad7c4b.

@ramondeklein ramondeklein requested a review from cesnietor March 13, 2025 19:41
@cesnietor
Copy link
Collaborator

Now disablebucket is failing :D @ramondeklein

--- FAIL: Test_disableBucketEncryption (0.00s)
    --- FAIL: Test_disableBucketEncryption/Bucket_encryption_disabled_correctly (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1327fb8]

goroutine 180 [running]:
testing.tRunner.func1.2({0x1465b20, 0x236b050})
	/opt/hostedtoolcache/go/1.23.7/x64/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
	/opt/hostedtoolcache/go/1.23.7/x64/src/testing/testing.go:1635 +0x35e
panic({0x1465b20?, 0x236b050?})
	/opt/hostedtoolcache/go/1.23.7/x64/src/runtime/panic.go:791 +0x132
github.com/minio/console/api.minioClientMock.removeBucketEncryption(...)
	/home/runner/work/console/console/api/user_buckets_test.go:118
github.com/minio/console/api.disableBucketEncryption(...)
	/home/runner/work/console/console/api/user_buckets.go:499
github.com/minio/console/api.Test_disableBucketEncryption.func3(0xc000350680?)
	/home/runner/work/console/console/api/user_buckets_test.go:457 +0x90
testing.tRunner(0xc000350680, 0xc0000d4c40)
	/opt/hostedtoolcache/go/1.23.7/x64/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 179
	/opt/hostedtoolcache/go/1.23.7/x64/src/testing/testing.go:1743 +0x390

@ramondeklein
Copy link
Collaborator Author

@cesnietor Sorry, I didn't check it right. All checks now pass...

@bexsoft bexsoft merged commit 71b1b70 into minio:master Mar 21, 2025
28 checks passed
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.

3 participants