@@ -33,6 +33,7 @@ import (
33
33
func TestCoordinatorExpectedDiagnosticHooks (t * testing.T ) {
34
34
35
35
expected := []string {
36
+ "agent-info" ,
36
37
"local-config" ,
37
38
"pre-config" ,
38
39
"variables" ,
@@ -128,6 +129,39 @@ fleet:
128
129
assert .YAMLEq (t , expectedCfg , string (result ), "local-config diagnostic returned unexpected value" )
129
130
}
130
131
132
+ func TestDiagnosticAgentInfo (t * testing.T ) {
133
+ // Create a coordinator with an info.Agent and ensure its included in diagnostics.
134
+
135
+ coord := & Coordinator {agentInfo : fakeAgentInfo {
136
+ agentID : "agent-id" ,
137
+ headers : map [string ]string {
138
+ "header1" : "value1" ,
139
+ "header2" : "value2" ,
140
+ },
141
+ logLevel : "trace" ,
142
+ snapshot : true ,
143
+ version : "8.14.0" ,
144
+ unprivileged : true ,
145
+ }}
146
+
147
+ expected := `
148
+ agent_id: agent-id
149
+ headers:
150
+ header1: value1
151
+ header2: value2
152
+ log_level: trace
153
+ snapshot: true
154
+ version: 8.14.0
155
+ unprivileged: true
156
+ `
157
+
158
+ hook , ok := diagnosticHooksMap (coord )["agent-info" ]
159
+ require .True (t , ok , "diagnostic hooks should have an entry for agent-info" )
160
+
161
+ result := hook .Hook (context .Background ())
162
+ assert .YAMLEq (t , expected , string (result ), "agent-info diagnostic returned unexpected value" )
163
+ }
164
+
131
165
func TestDiagnosticPreConfig (t * testing.T ) {
132
166
// Create a coordinator with a test AST and make sure it's returned
133
167
// by the pre-config diagnostic.
@@ -589,3 +623,39 @@ func mapFromRawYAML(t *testing.T, str string) map[string]interface{} {
589
623
require .NoError (t , err , "Parsing of YAML test string must succeed" )
590
624
return result
591
625
}
626
+
627
+ type fakeAgentInfo struct {
628
+ agentID string
629
+ headers map [string ]string
630
+ logLevel string
631
+ snapshot bool
632
+ version string
633
+ unprivileged bool
634
+ }
635
+
636
+ func (a fakeAgentInfo ) AgentID () string {
637
+ return a .agentID
638
+ }
639
+
640
+ func (a fakeAgentInfo ) Headers () map [string ]string {
641
+ return a .headers
642
+ }
643
+
644
+ func (a fakeAgentInfo ) LogLevel () string {
645
+ return a .logLevel
646
+ }
647
+
648
+ func (a fakeAgentInfo ) Snapshot () bool {
649
+ return a .snapshot
650
+ }
651
+
652
+ func (a fakeAgentInfo ) Version () string {
653
+ return a .version
654
+ }
655
+
656
+ func (a fakeAgentInfo ) Unprivileged () bool {
657
+ return a .unprivileged
658
+ }
659
+
660
+ func (a fakeAgentInfo ) ReloadID (ctx context.Context ) error { panic ("implement me" ) }
661
+ func (a fakeAgentInfo ) SetLogLevel (ctx context.Context , level string ) error { panic ("implement me" ) }
0 commit comments