@@ -89,3 +89,135 @@ func TestConnectionOutputMapper(t *testing.T) {
8989
9090 tests .Execute (t , item )
9191}
92+
93+ func TestConnectionInputMapperSearch (t * testing.T ) {
94+ adapter := NewNetworkManagerConnectionAdapter (& networkmanager.Client {}, "123456789012" )
95+
96+ tests := []struct {
97+ name string
98+ query string
99+ expectedInput * networkmanager.GetConnectionsInput
100+ expectError bool
101+ }{
102+ {
103+ name : "Valid networkmanager-connection ARN" ,
104+ query : "arn:aws:networkmanager::123456789012:device/global-network-0d47f6t230mz46dy4/connection-07f6fd08867abc123" ,
105+ expectedInput : & networkmanager.GetConnectionsInput {
106+ GlobalNetworkId : adapterhelpers .PtrString ("global-network-0d47f6t230mz46dy4" ),
107+ ConnectionIds : []string {"connection-07f6fd08867abc123" },
108+ },
109+ expectError : false ,
110+ },
111+ {
112+ name : "Valid networkmanager-device ARN" ,
113+ query : "arn:aws:networkmanager::123456789012:device/global-network-01231231231231231/device-07f6fd08867abc123" ,
114+ expectedInput : & networkmanager.GetConnectionsInput {
115+ GlobalNetworkId : adapterhelpers .PtrString ("global-network-01231231231231231" ),
116+ DeviceId : adapterhelpers .PtrString ("device-07f6fd08867abc123" ),
117+ },
118+ expectError : false ,
119+ },
120+ {
121+ name : "Global Network ID only" ,
122+ query : "global-network-123456789" ,
123+ expectedInput : & networkmanager.GetConnectionsInput {
124+ GlobalNetworkId : adapterhelpers .PtrString ("global-network-123456789" ),
125+ },
126+ expectError : false ,
127+ },
128+ {
129+ name : "Global Network ID and Device ID" ,
130+ query : "global-network-123456789|device-987654321" ,
131+ expectedInput : & networkmanager.GetConnectionsInput {
132+ GlobalNetworkId : adapterhelpers .PtrString ("global-network-123456789" ),
133+ DeviceId : adapterhelpers .PtrString ("device-987654321" ),
134+ },
135+ expectError : false ,
136+ },
137+ {
138+ name : "Invalid ARN - wrong service" ,
139+ query : "arn:aws:ec2::123456789012:instance/i-1234567890abcdef0" ,
140+ expectError : true ,
141+ },
142+ {
143+ name : "Invalid ARN - wrong resource type" ,
144+ query : "arn:aws:networkmanager::123456789012:site/global-network-01231231231231231/site-444555aaabbb11223" ,
145+ expectError : true ,
146+ },
147+ {
148+ name : "Invalid connection ARN - malformed resource" ,
149+ query : "arn:aws:networkmanager::123456789012:device/invalid-format" ,
150+ expectError : true ,
151+ },
152+ {
153+ name : "Invalid device ARN - malformed resource" ,
154+ query : "arn:aws:networkmanager::123456789012:device/global-network-123/invalid-prefix-123" ,
155+ expectError : true ,
156+ },
157+ {
158+ name : "Invalid query - too many sections" ,
159+ query : "section1|section2|section3" ,
160+ expectError : true ,
161+ },
162+ }
163+
164+ for _ , tt := range tests {
165+ t .Run (tt .name , func (t * testing.T ) {
166+ input , err := adapter .InputMapperSearch (context .Background (), & networkmanager.Client {}, "123456789012.us-east-1" , tt .query )
167+
168+ if tt .expectError {
169+ if err == nil {
170+ t .Errorf ("Expected error for query %s, but got none" , tt .query )
171+ }
172+ return
173+ }
174+
175+ if err != nil {
176+ t .Errorf ("Unexpected error for query %s: %v" , tt .query , err )
177+ return
178+ }
179+
180+ if input == nil {
181+ t .Errorf ("Expected input but got nil for query %s" , tt .query )
182+ return
183+ }
184+
185+ // Compare GlobalNetworkId
186+ if (input .GlobalNetworkId == nil ) != (tt .expectedInput .GlobalNetworkId == nil ) {
187+ t .Errorf ("GlobalNetworkId nil mismatch for query %s" , tt .query )
188+ return
189+ }
190+ if input .GlobalNetworkId != nil && tt .expectedInput .GlobalNetworkId != nil {
191+ if * input .GlobalNetworkId != * tt .expectedInput .GlobalNetworkId {
192+ t .Errorf ("Expected GlobalNetworkId %s, got %s for query %s" ,
193+ * tt .expectedInput .GlobalNetworkId , * input .GlobalNetworkId , tt .query )
194+ }
195+ }
196+
197+ // Compare DeviceId
198+ if (input .DeviceId == nil ) != (tt .expectedInput .DeviceId == nil ) {
199+ t .Errorf ("DeviceId nil mismatch for query %s" , tt .query )
200+ return
201+ }
202+ if input .DeviceId != nil && tt .expectedInput .DeviceId != nil {
203+ if * input .DeviceId != * tt .expectedInput .DeviceId {
204+ t .Errorf ("Expected DeviceId %s, got %s for query %s" ,
205+ * tt .expectedInput .DeviceId , * input .DeviceId , tt .query )
206+ }
207+ }
208+
209+ // Compare ConnectionIds
210+ if len (input .ConnectionIds ) != len (tt .expectedInput .ConnectionIds ) {
211+ t .Errorf ("Expected %d ConnectionIds, got %d for query %s" ,
212+ len (tt .expectedInput .ConnectionIds ), len (input .ConnectionIds ), tt .query )
213+ return
214+ }
215+ for i , connectionId := range input .ConnectionIds {
216+ if connectionId != tt .expectedInput .ConnectionIds [i ] {
217+ t .Errorf ("Expected ConnectionId %s, got %s at index %d for query %s" ,
218+ tt .expectedInput .ConnectionIds [i ], connectionId , i , tt .query )
219+ }
220+ }
221+ })
222+ }
223+ }
0 commit comments