CloudWatch: Refactor around handleGetRegions (#65713)

* Create minimal EC2 interface

* convert regions variable to a function returning a copy

* Add test for multiple calls to regions to check regionsCache

* Add returns to handler after error

* Refactor handleGetRegions
This commit is contained in:
Shirley
2023-04-11 19:55:57 +02:00
committed by GitHub
parent 92e591d2e1
commit ae23ef5b41
8 changed files with 129 additions and 42 deletions
+14
View File
@@ -106,6 +106,20 @@ func (c *fakeCWAnnotationsClient) DescribeAlarms(params *cloudwatch.DescribeAlar
return c.describeAlarmsOutput, nil
}
type mockEC2Client struct {
mock.Mock
}
func (c *mockEC2Client) DescribeRegions(in *ec2.DescribeRegionsInput) (*ec2.DescribeRegionsOutput, error) {
args := c.Called(in)
return args.Get(0).(*ec2.DescribeRegionsOutput), args.Error(1)
}
func (c *mockEC2Client) DescribeInstancesPages(in *ec2.DescribeInstancesInput, fn func(*ec2.DescribeInstancesOutput, bool) bool) error {
args := c.Called(in, fn)
return args.Error(0)
}
type fakeEC2Client struct {
ec2iface.EC2API