@@ -78,6 +78,13 @@ func defaultConnectingHandler(connectionCallbacks types.ConnectionCallbacks) fun
78
78
}
79
79
}
80
80
81
+ func getAgentLogs (t * testing.T , storageDir string ) string {
82
+ agentLogFile := filepath .Join (storageDir , "agent.log" )
83
+ agentLog , err := os .ReadFile (agentLogFile )
84
+ require .NoError (t , err )
85
+ return string (agentLog )
86
+ }
87
+
81
88
// onConnectingFuncFactory is a function that will be given to types.ConnectionCallbacks as
82
89
// OnConnectingFunc. This allows changing the ConnectionCallbacks both from the newOpAMPServer
83
90
// caller and inside of newOpAMP Server, and for custom implementations of the value for `Accept`
@@ -274,6 +281,53 @@ func TestSupervisorStartsCollectorWithRemoteConfig(t *testing.T) {
274
281
}, 10 * time .Second , 500 * time .Millisecond , "Log never appeared in output" )
275
282
}
276
283
284
+ func TestSupervisorStartsCollectorWithLocalConfigOnly (t * testing.T ) {
285
+ connected := atomic.Bool {}
286
+ server := newOpAMPServer (t , defaultConnectingHandler , types.ConnectionCallbacks {
287
+ OnConnected : func (_ context.Context , _ types.Connection ) {
288
+ connected .Store (true )
289
+ },
290
+ })
291
+
292
+ cfg , _ , inputFile , outputFile := createSimplePipelineCollectorConf (t )
293
+
294
+ collectorConfigDir := t .TempDir ()
295
+ cfgFile , err := os .CreateTemp (collectorConfigDir , "config_*.yaml" )
296
+ t .Cleanup (func () { cfgFile .Close () })
297
+ require .NoError (t , err )
298
+
299
+ _ , err = cfgFile .Write (cfg .Bytes ())
300
+ require .NoError (t , err )
301
+
302
+ storageDir := t .TempDir ()
303
+
304
+ s := newSupervisor (t , "basic" , map [string ]string {
305
+ "url" : server .addr ,
306
+ "storage_dir" : storageDir ,
307
+ "local_config" : cfgFile .Name (),
308
+ })
309
+ t .Cleanup (s .Shutdown )
310
+ require .NoError (t , s .Start ())
311
+
312
+ waitForSupervisorConnection (server .supervisorConnected , true )
313
+ require .True (t , connected .Load (), "Supervisor failed to connect" )
314
+
315
+ require .EventuallyWithTf (t , func (c * assert.CollectT ) {
316
+ require .Contains (c , getAgentLogs (t , storageDir ), "Connected to the OpAMP server" )
317
+ }, 10 * time .Second , 500 * time .Millisecond , "Collector did not connected to the OpAMP server" )
318
+
319
+ n , err := inputFile .WriteString ("{\" body\" :\" hello, world\" }\n " )
320
+ require .NotZero (t , n , "Could not write to input file" )
321
+ require .NoError (t , err )
322
+
323
+ require .Eventually (t , func () bool {
324
+ logRecord := make ([]byte , 1024 )
325
+ n , _ := outputFile .Read (logRecord )
326
+
327
+ return n != 0
328
+ }, 10 * time .Second , 500 * time .Millisecond , "Log never appeared in output" )
329
+ }
330
+
277
331
func TestSupervisorStartsCollectorWithNoOpAMPServerWithNoLastRemoteConfig (t * testing.T ) {
278
332
storageDir := t .TempDir ()
279
333
t .Log ("Storage dir:" , storageDir )
0 commit comments