@@ -74,6 +74,87 @@ func TestFleetServerComponentModifier_NoServerConfig(t *testing.T) {
74
74
}
75
75
}
76
76
77
+ func TestFleetServerComponentModifier (t * testing.T ) {
78
+ tests := []struct {
79
+ name string
80
+ source map [string ]interface {}
81
+ expect map [string ]interface {}
82
+ }{{
83
+ name : "empty output component" ,
84
+ source : map [string ]interface {}{},
85
+ expect : map [string ]interface {}{
86
+ "bootstrap" : map [string ]interface {}{
87
+ "protocol" : "https" ,
88
+ "hosts" : []interface {}{"elasticsearch:9200" },
89
+ "service_token" : "example-token" ,
90
+ },
91
+ },
92
+ }, {
93
+ name : "output component provided" ,
94
+ source : map [string ]interface {}{
95
+ "protocol" : "http" ,
96
+ "hosts" : []interface {}{"elasticsearch:9200" , "host:9200" },
97
+ },
98
+ expect : map [string ]interface {}{
99
+ "protocol" : "http" ,
100
+ "hosts" : []interface {}{"elasticsearch:9200" , "host:9200" },
101
+ "bootstrap" : map [string ]interface {}{
102
+ "protocol" : "https" ,
103
+ "hosts" : []interface {}{"elasticsearch:9200" },
104
+ "service_token" : "example-token" ,
105
+ },
106
+ },
107
+ }}
108
+ cfg := & configuration.FleetServerConfig {
109
+ Output : configuration.FleetServerOutputConfig {
110
+ Elasticsearch : configuration.Elasticsearch {
111
+ Protocol : "https" ,
112
+ Hosts : []string {"elasticsearch:9200" },
113
+ ServiceToken : "example-token" ,
114
+ },
115
+ },
116
+ }
117
+ modifier := FleetServerComponentModifier (cfg )
118
+
119
+ for _ , tc := range tests {
120
+ t .Run (tc .name , func (t * testing.T ) {
121
+ src , err := structpb .NewStruct (tc .source )
122
+ require .NoError (t , err )
123
+ comps , err := modifier ([]component.Component {{
124
+ InputSpec : & component.InputRuntimeSpec {
125
+ InputType : "fleet-server" ,
126
+ },
127
+ Units : []component.Unit {{
128
+ Type : client .UnitTypeOutput ,
129
+ Config : & proto.UnitExpectedConfig {
130
+ Type : "elasticsearch" ,
131
+ Source : src ,
132
+ },
133
+ }},
134
+ }}, nil )
135
+ require .NoError (t , err )
136
+
137
+ require .Len (t , comps , 1 )
138
+ require .Len (t , comps [0 ].Units , 1 )
139
+ res := comps [0 ].Units [0 ].Config .Source .AsMap ()
140
+ for k , v := range tc .expect {
141
+ val , ok := res [k ]
142
+ require .Truef (t , ok , "expected %q to be in output unit config" , k )
143
+ if mp , ok := v .(map [string ]interface {}); ok {
144
+ rMap , ok := val .(map [string ]interface {})
145
+ require .Truef (t , ok , "expected %q to be map[string]interface{} was %T" , k , val )
146
+ for kk , vv := range mp {
147
+ assert .Contains (t , rMap , kk )
148
+ assert .Equal (t , rMap [kk ], vv )
149
+ }
150
+ } else {
151
+ assert .Equal (t , v , val )
152
+ }
153
+ }
154
+ })
155
+ }
156
+ }
157
+
77
158
func TestInjectFleetConfigComponentModifier (t * testing.T ) {
78
159
fleetConfig := & configuration.FleetAgentConfig {
79
160
Enabled : true ,
0 commit comments