-
Notifications
You must be signed in to change notification settings - Fork 131
fix: handle nil AWS ALB entries #758
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: dev
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ import ( | |
| func processLoadBalancersForTest(lbs []*elbv2.LoadBalancer) *schema.Resources { | ||
| list := schema.NewResources() | ||
| for _, lb := range lbs { | ||
| if lb.DNSName == nil || lb.LoadBalancerName == nil { | ||
| if lb == nil || lb.DNSName == nil || lb.LoadBalancerName == nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift Exercise the production listing path.
Use a mocked ELBv2 client to call the production method, or extract the shared filtering logic into a production helper. Express the nil and incomplete cases as table-driven inputs. As per coding guidelines, provider tests should prefer mocked cloud provider clients and use table-driven tests for resource parsing. Also applies to: 44-48 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| continue | ||
| } | ||
| list.Append(&schema.Resource{ | ||
|
|
@@ -41,10 +41,11 @@ func processTargetsForTest(targets []*elbv2.TargetHealthDescription) []string { | |
| return ids | ||
| } | ||
|
|
||
| func TestListELBV2Resources_NilDNSName(t *testing.T) { | ||
| func TestListELBV2Resources_NilLoadBalancer(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| lbs := []*elbv2.LoadBalancer{ | ||
| nil, | ||
| { | ||
| DNSName: nil, | ||
| LoadBalancerName: aws.String("internal-lb"), | ||
|
|
@@ -58,7 +59,7 @@ func TestListELBV2Resources_NilDNSName(t *testing.T) { | |
|
|
||
| require.NotPanics(t, func() { | ||
| resources := processLoadBalancersForTest(lbs) | ||
| assert.Equal(t, 0, len(resources.Items), "nil DNSName or LoadBalancerName LBs must be skipped") | ||
| assert.Equal(t, 0, len(resources.Items), "nil or incomplete load balancers must be skipped") | ||
| }) | ||
| } | ||
|
|
||
|
|
||
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.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Reject empty DNS values, not only nil pointers.
The guard on Line 77 only checks whether
DNSNameis non-nil.aws.String("")is non-nil. IfLoadBalancerNameis populated, the loop emits a resource with an emptyDNSName.Check the pointed-to DNS value before constructing the resource.
Proposed fix
As per coding guidelines, each emitted resource must have at least one of IP or DNS populated; empty resources are invalid.
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Coding guidelines