Skip to content

Commit 4cba875

Browse files
test(cpo): add unit test for isAWSThrottleError
Improve codecov patch coverage by testing all throttle error codes and negative cases (non-throttle AWS errors, non-AWS errors, nil). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 075a301 commit 4cba875

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

control-plane-operator/controllers/awsprivatelink/awsprivatelink_controller_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,3 +1920,56 @@ func TestReconcileEndpointDNSRecords(t *testing.T) {
19201920
})
19211921
}
19221922
}
1923+
1924+
func TestIsAWSThrottleError(t *testing.T) {
1925+
tests := []struct {
1926+
name string
1927+
err error
1928+
expected bool
1929+
}{
1930+
{
1931+
name: "Throttling error should be detected",
1932+
err: &testAPIError{code: "Throttling"},
1933+
expected: true,
1934+
},
1935+
{
1936+
name: "ThrottlingException should be detected",
1937+
err: &testAPIError{code: "ThrottlingException"},
1938+
expected: true,
1939+
},
1940+
{
1941+
name: "RequestLimitExceeded should be detected",
1942+
err: &testAPIError{code: "RequestLimitExceeded"},
1943+
expected: true,
1944+
},
1945+
{
1946+
name: "TooManyRequestsException should be detected",
1947+
err: &testAPIError{code: "TooManyRequestsException"},
1948+
expected: true,
1949+
},
1950+
{
1951+
name: "Non-throttle AWS error should not be detected",
1952+
err: &testAPIError{code: "NoSuchHostedZone"},
1953+
expected: false,
1954+
},
1955+
{
1956+
name: "Non-AWS error should not be detected",
1957+
err: errors.New("network error"),
1958+
expected: false,
1959+
},
1960+
{
1961+
name: "Nil error should not be detected",
1962+
err: nil,
1963+
expected: false,
1964+
},
1965+
}
1966+
1967+
for _, tt := range tests {
1968+
t.Run(tt.name, func(t *testing.T) {
1969+
result := isAWSThrottleError(tt.err)
1970+
if result != tt.expected {
1971+
t.Errorf("isAWSThrottleError() = %v, want %v", result, tt.expected)
1972+
}
1973+
})
1974+
}
1975+
}

0 commit comments

Comments
 (0)