@@ -21,11 +21,14 @@ import (
21
21
22
22
type mockrdsServiceConfigurer func (k * MockrdsService )
23
23
24
+ const defaultDbmTag = "datadoghq.com/dbm:true"
25
+
24
26
func TestGetAuroraClusterEndpoints (t * testing.T ) {
25
27
testCases := []struct {
26
28
name string
27
29
configureClient mockrdsServiceConfigurer
28
30
clusterIDs []string
31
+ dbmTag * string
29
32
expectedAuroraClusterEndpoints map [string ]* AuroraCluster
30
33
expectedErr error
31
34
}{
@@ -87,6 +90,80 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
87
90
},
88
91
},
89
92
},
93
+ {
94
+ name : "single cluster id returns single endpoint from API with custom DBM tag" ,
95
+ configureClient : func (k * MockrdsService ) {
96
+ k .EXPECT ().DescribeDBInstances (gomock .Any (), gomock .Any ()).Return (& rds.DescribeDBInstancesOutput {
97
+ DBInstances : []types.DBInstance {
98
+ {
99
+ Endpoint : & types.Endpoint {
100
+ Address : aws .String ("test-endpoint" ),
101
+ Port : aws .Int32 (5432 ),
102
+ },
103
+ DBClusterIdentifier : aws .String ("test-cluster" ),
104
+ IAMDatabaseAuthenticationEnabled : aws .Bool (true ),
105
+ AvailabilityZone : aws .String ("us-east-1a" ),
106
+ DBInstanceStatus : aws .String ("available" ),
107
+ Engine : aws .String ("aurora-postgresql" ),
108
+ TagList : []types.Tag {{Key : aws .String ("datadoghq.com/dbm" ), Value : aws .String ("custom" )}},
109
+ },
110
+ },
111
+ }, nil ).Times (1 )
112
+ },
113
+ clusterIDs : []string {"test-cluster" },
114
+ dbmTag : aws .String ("datadoghq.com/dbm:custom" ),
115
+ expectedAuroraClusterEndpoints : map [string ]* AuroraCluster {
116
+ "test-cluster" : {
117
+ Instances : []* Instance {
118
+ {
119
+ Endpoint : "test-endpoint" ,
120
+ Port : 5432 ,
121
+ IamEnabled : true ,
122
+ Engine : "aurora-postgresql" ,
123
+ DbName : "postgres" ,
124
+ DbmEnabled : true ,
125
+ },
126
+ },
127
+ },
128
+ },
129
+ },
130
+ {
131
+ name : "single cluster id returns single endpoint from API with custom bare DBM tag" ,
132
+ configureClient : func (k * MockrdsService ) {
133
+ k .EXPECT ().DescribeDBInstances (gomock .Any (), gomock .Any ()).Return (& rds.DescribeDBInstancesOutput {
134
+ DBInstances : []types.DBInstance {
135
+ {
136
+ Endpoint : & types.Endpoint {
137
+ Address : aws .String ("test-endpoint" ),
138
+ Port : aws .Int32 (5432 ),
139
+ },
140
+ DBClusterIdentifier : aws .String ("test-cluster" ),
141
+ IAMDatabaseAuthenticationEnabled : aws .Bool (true ),
142
+ AvailabilityZone : aws .String ("us-east-1a" ),
143
+ DBInstanceStatus : aws .String ("available" ),
144
+ Engine : aws .String ("aurora-postgresql" ),
145
+ TagList : []types.Tag {{Key : aws .String ("datadoghq.com/dbm" )}},
146
+ },
147
+ },
148
+ }, nil ).Times (1 )
149
+ },
150
+ clusterIDs : []string {"test-cluster" },
151
+ dbmTag : aws .String ("datadoghq.com/dbm" ),
152
+ expectedAuroraClusterEndpoints : map [string ]* AuroraCluster {
153
+ "test-cluster" : {
154
+ Instances : []* Instance {
155
+ {
156
+ Endpoint : "test-endpoint" ,
157
+ Port : 5432 ,
158
+ IamEnabled : true ,
159
+ Engine : "aurora-postgresql" ,
160
+ DbName : "postgres" ,
161
+ DbmEnabled : true ,
162
+ },
163
+ },
164
+ },
165
+ },
166
+ },
90
167
{
91
168
name : "single cluster id returns many endpoints from API" ,
92
169
configureClient : func (k * MockrdsService ) {
@@ -265,6 +342,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
265
342
AvailabilityZone : aws .String ("us-east-1a" ),
266
343
DBInstanceStatus : aws .String ("available" ),
267
344
Engine : aws .String ("aurora-postgresql" ),
345
+ TagList : []types.Tag {{Key : aws .String ("datadoghq.com/dbm" ), Value : aws .String ("true" )}},
268
346
},
269
347
{
270
348
Endpoint : & types.Endpoint {
@@ -306,6 +384,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
306
384
IamEnabled : true ,
307
385
Engine : "aurora-postgresql" ,
308
386
DbName : "postgres" ,
387
+ DbmEnabled : true ,
309
388
},
310
389
{
311
390
Endpoint : "test-endpoint-2" ,
@@ -337,7 +416,11 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
337
416
mockClient := NewMockrdsService (ctrl )
338
417
tt .configureClient (mockClient )
339
418
client := & Client {client : mockClient }
340
- clusters , err := client .GetAuroraClusterEndpoints (context .Background (), tt .clusterIDs )
419
+ dbmTag := defaultDbmTag
420
+ if tt .dbmTag != nil {
421
+ dbmTag = * tt .dbmTag
422
+ }
423
+ clusters , err := client .GetAuroraClusterEndpoints (context .Background (), tt .clusterIDs , dbmTag )
341
424
if tt .expectedErr != nil {
342
425
assert .EqualError (t , err , tt .expectedErr .Error ())
343
426
return
@@ -510,7 +593,7 @@ func TestGetAuroraClusterEndpointsDbName(t *testing.T) {
510
593
mockClient := NewMockrdsService (ctrl )
511
594
tt .configureClient (mockClient )
512
595
client := & Client {client : mockClient }
513
- clusters , err := client .GetAuroraClusterEndpoints (context .Background (), tt .clusterIDs )
596
+ clusters , err := client .GetAuroraClusterEndpoints (context .Background (), tt .clusterIDs , defaultDbmTag )
514
597
if tt .expectedErr != nil {
515
598
assert .EqualError (t , err , tt .expectedErr .Error ())
516
599
return
0 commit comments