@@ -171,6 +171,75 @@ func TestLogWebhook(t *testing.T) {
171171 return log .Error
172172 },
173173 },
174+ {
175+ name : "success - lifecycle event type matches" ,
176+ numReqs : 2 ,
177+ cfg : api.SystemSettingsLog {
178+ Name : "webhook" ,
179+ Type : api .LogTypeWebhook ,
180+ Level : "warn" ,
181+ Address : "*" ,
182+ RetryCount : 3 ,
183+ RetryTimeout : api .AsDuration (10 * time .Second ),
184+ Scopes : []api.LogScope {api .LogScopeLifecycle , api .LogScopeLogging },
185+ LifecycleActions : []api.LifecycleAction {event .MigrationCreated },
186+ },
187+ instanceData : api.Instance {
188+ Source : "src1" ,
189+ InstanceProperties : api.InstanceProperties {
190+ UUID : uuidA ,
191+ Location : "/path/to/instance1" ,
192+ InstancePropertiesConfigurable : api.InstancePropertiesConfigurable {Name : "instance1" },
193+ NICs : []api.InstancePropertiesNIC {{UUID : uuidB }, {UUID : uuidC }},
194+ },
195+ },
196+ queueData : api.QueueEntry {
197+ InstanceUUID : uuidA ,
198+ InstanceName : "instance1" ,
199+ BatchName : "batch1" ,
200+ MigrationWindow : api.MigrationWindow {Name : "window1" , Config : api.MigrationWindowConfig {Capacity : 10 }},
201+ Placement : api.Placement {TargetName : "tgt1" },
202+ },
203+
204+ wantResps : []api.Event {
205+ {Type : api .LogScopeLifecycle , Metadata : []byte ("lifecycle" )}, // apply wantLifecycle
206+ defaultLog ,
207+ },
208+ wantLifecycle : api.EventLifecycle {
209+ Action : string (event .MigrationCreated ),
210+ Entities : []string {
211+ "/1.0/queue/" + uuidA .String (),
212+ "/1.0/instances/" + uuidA .String (),
213+ "/1.0/batches/batch1" ,
214+ "/1.0/sources/src1" ,
215+ "/1.0/targets/tgt1" ,
216+ "/1.0/networks/" + uuidB .String (),
217+ "/1.0/networks/" + uuidC .String (),
218+ },
219+ Metadata : []byte ("*" ), // apply objects
220+ },
221+ sendLog : func (log * slog.Logger ) func (msg string , args ... any ) {
222+ return log .Error
223+ },
224+ },
225+ {
226+ name : "success - lifecycle event type does not match" ,
227+ numReqs : 1 ,
228+ cfg : api.SystemSettingsLog {
229+ Name : "webhook" ,
230+ Type : api .LogTypeWebhook ,
231+ Level : "warn" ,
232+ Address : "*" ,
233+ RetryCount : 3 ,
234+ RetryTimeout : api .AsDuration (10 * time .Second ),
235+ Scopes : []api.LogScope {api .LogScopeLifecycle , api .LogScopeLogging },
236+ LifecycleActions : []api.LifecycleAction {event .InstanceImported },
237+ },
238+ wantResps : []api.Event {defaultLog },
239+ sendLog : func (log * slog.Logger ) func (msg string , args ... any ) {
240+ return log .Error
241+ },
242+ },
174243 {
175244 name : "success - discard log level" ,
176245 numReqs : 0 ,
0 commit comments