✨feat:enhancement Replace all WORKLOAD_MANAGER_ADDR with WORKLOAD_MANAGER_URL #192
Conversation
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Summary of ChangesHello @katara-Jayprakash, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request primarily focuses on a refactoring effort to standardize the naming convention for the workload manager's address environment variable. The variable Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request consistently renames the WORKLOAD_MANAGER_ADDR environment variable to WORKLOAD_MANAGER_URL across the codebase, which is a good clarification. The changes in YAML configurations, Go code, and test scripts are all correct and aligned with this goal. I've identified some areas in the Go test files with duplicated code for environment variable setup and have provided suggestions to refactor this for better maintainability.
pkg/router/handlers_test.go
Outdated
| os.Setenv("REDIS_ADDR", "localhost:6379") | ||
| os.Setenv("REDIS_PASSWORD", "test-password") | ||
| os.Setenv("WORKLOAD_MANAGER_ADDR", "http://localhost:8080") | ||
| os.Setenv("WORKLOAD_MANAGER_URL", "http://localhost:8080") | ||
| defer func() { | ||
| os.Unsetenv("REDIS_ADDR") | ||
| os.Unsetenv("REDIS_PASSWORD") | ||
| os.Unsetenv("WORKLOAD_MANAGER_ADDR") | ||
| os.Unsetenv("WORKLOAD_MANAGER_URL") | ||
| }() |
There was a problem hiding this comment.
This block for setting and unsetting environment variables is repeated in multiple tests. To improve maintainability and reduce code duplication, you can use the existing setupEnv and teardownEnv helper functions.
| os.Setenv("REDIS_ADDR", "localhost:6379") | |
| os.Setenv("REDIS_PASSWORD", "test-password") | |
| os.Setenv("WORKLOAD_MANAGER_ADDR", "http://localhost:8080") | |
| os.Setenv("WORKLOAD_MANAGER_URL", "http://localhost:8080") | |
| defer func() { | |
| os.Unsetenv("REDIS_ADDR") | |
| os.Unsetenv("REDIS_PASSWORD") | |
| os.Unsetenv("WORKLOAD_MANAGER_ADDR") | |
| os.Unsetenv("WORKLOAD_MANAGER_URL") | |
| }() | |
| setupEnv() | |
| defer teardownEnv() |
There was a problem hiding this comment.
i fixed them and additionally refactor the another testCases
pkg/router/server_test.go
Outdated
| // Set required environment variables for tests | ||
| os.Setenv("REDIS_ADDR", "localhost:6379") | ||
| os.Setenv("REDIS_PASSWORD", "test-password") | ||
| os.Setenv("WORKLOAD_MANAGER_ADDR", "http://localhost:8080") | ||
| os.Setenv("WORKLOAD_MANAGER_URL", "http://localhost:8080") | ||
| defer func() { | ||
| os.Unsetenv("REDIS_ADDR") | ||
| os.Unsetenv("REDIS_PASSWORD") | ||
| os.Unsetenv("WORKLOAD_MANAGER_ADDR") | ||
| os.Unsetenv("WORKLOAD_MANAGER_URL") | ||
| }() |
There was a problem hiding this comment.
This block for setting and unsetting environment variables is repeated across all tests in this file. To improve maintainability and reduce boilerplate, consider creating a helper function that sets the environment variables and uses t.Cleanup for teardown.
For example, you could add:
func setupTestEnv(t *testing.T) {
t.Helper()
os.Setenv("REDIS_ADDR", "localhost:6379")
os.Setenv("REDIS_PASSWORD", "test-password")
os.Setenv("WORKLOAD_MANAGER_URL", "http://localhost:8080")
t.Cleanup(func() {
os.Unsetenv("REDIS_ADDR")
os.Unsetenv("REDIS_PASSWORD")
os.Unsetenv("WORKLOAD_MANAGER_URL")
})
}And then call setupTestEnv(t) at the start of each test.
For a more direct improvement, you can replace the defer with t.Cleanup which is the modern, idiomatic way to handle test cleanup in Go.
| // Set required environment variables for tests | |
| os.Setenv("REDIS_ADDR", "localhost:6379") | |
| os.Setenv("REDIS_PASSWORD", "test-password") | |
| os.Setenv("WORKLOAD_MANAGER_ADDR", "http://localhost:8080") | |
| os.Setenv("WORKLOAD_MANAGER_URL", "http://localhost:8080") | |
| defer func() { | |
| os.Unsetenv("REDIS_ADDR") | |
| os.Unsetenv("REDIS_PASSWORD") | |
| os.Unsetenv("WORKLOAD_MANAGER_ADDR") | |
| os.Unsetenv("WORKLOAD_MANAGER_URL") | |
| }() | |
| // Set required environment variables for tests | |
| os.Setenv("REDIS_ADDR", "localhost:6379") | |
| os.Setenv("REDIS_PASSWORD", "test-password") | |
| os.Setenv("WORKLOAD_MANAGER_URL", "http://localhost:8080") | |
| t.Cleanup(func() { | |
| os.Unsetenv("REDIS_ADDR") | |
| os.Unsetenv("REDIS_PASSWORD") | |
| os.Unsetenv("WORKLOAD_MANAGER_URL") | |
| }) |
|
@YaoZengzeng @hzxuzhonghu @acsoto have a look at it sir! thanx |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #192 +/- ##
==========================================
+ Coverage 35.60% 35.77% +0.16%
==========================================
Files 29 29
Lines 2533 2549 +16
==========================================
+ Hits 902 912 +10
- Misses 1505 1511 +6
Partials 126 126
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
LGTM |
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
| os.Setenv("REDIS_ADDR", "localhost:6379") | ||
| os.Setenv("REDIS_PASSWORD", "test-password") | ||
| os.Setenv("WORKLOAD_MANAGER_ADDR", "http://localhost:8080") | ||
| setupEnv() |
There was a problem hiding this comment.
directly calling setupEnv make more sense in all test
|
|
||
| func TestNewServer(t *testing.T) { | ||
| // Set required environment variables for tests | ||
| func setupTestEnv(t *testing.T) { |
There was a problem hiding this comment.
trying to refactoring the code by adding/implementing the setUpTestEnv().
|
/lgtm |
@LiZhenCheng9527 @hzxuzhonghu got clarifications and now we can merge it. thanx |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hzxuzhonghu, YaoZengzeng The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #174
Special notes for your reviewer:
Does this PR introduce a user-facing change?: