-
Notifications
You must be signed in to change notification settings - Fork 160
Replace string matching with JSON parsing in isRemoteWorkload - issue - 2941 #2968
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
base: main
Are you sure you want to change the base?
Changes from all commits
8dd06ee
411ba02
aad19ae
e7bd60e
207c945
f9de1f3
7cb1318
159eb7b
a86f4f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1867,3 +1867,62 @@ func TestFileStatusManager_ListWorkloads_PIDMigration(t *testing.T) { | |
| require.NoError(t, err) | ||
| assert.Equal(t, existingPID, statusFile2.ProcessID, "PID should remain unchanged for second workload") | ||
| } | ||
|
|
||
| func TestFileStatusManager_IsRemoteWorkload_EdgeCases(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| configJSON string | ||
| expected bool | ||
| }{ | ||
| { | ||
| name: "remote workload with URL", | ||
| configJSON: `{"remote_url": "https://example.com"}`, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "local workload without remote_url field", | ||
| configJSON: `{"name": "test-workload"}`, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "edge case - remote_url in string value (false positive with old implementation)", | ||
| configJSON: `{"description": "Set \"remote_url\" in config to enable remote mode"}`, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "remote_url field is empty string", | ||
| configJSON: `{"remote_url": ""}`, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "remote_url field with whitespace only", | ||
| configJSON: `{"remote_url": " "}`, | ||
| expected: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| tt := tt | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Test the JSON parsing logic directly | ||
| var config struct { | ||
| RemoteURL string `json:"remote_url"` | ||
| } | ||
|
|
||
| err := json.Unmarshal([]byte(tt.configJSON), &config) | ||
| if err != nil { | ||
| t.Fatalf("failed to parse JSON: %v", err) | ||
| } | ||
|
|
||
| result := strings.TrimSpace(config.RemoteURL) != "" | ||
|
|
||
| if result != tt.expected { | ||
| t.Errorf("expected %v, got %v for JSON: %s", tt.expected, result, tt.configJSON) | ||
| } | ||
| }) | ||
| } | ||
|
Comment on lines
+1906
to
+1927
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test duplicates implementation logic instead of calling actual method
This test replicates the JSON parsing logic from
isRemoteWorkloadrather than calling the actual method. While this validates the parsing logic works, it doesn't provide regression protection if the method's behavior changes.Suggested improvement:
state.Storethat returns a reader with the test JSONfileStatusManagerwith the mock storemanager.isRemoteWorkload(ctx, workloadName)directlyboolanderrorThis would ensure the test exercises the full code path including store interaction, reader handling, and the defer cleanup.
Note: This is a low-priority suggestion - the existing tests for
GetWorkloaddo exerciseisRemoteWorkloadthrough integration paths, so there is some coverage.