@@ -163,24 +163,45 @@ func TestGetHostname(t *testing.T) {
163163}
164164
165165func TestDDAgentMultiAPIKeys (t * testing.T ) {
166+ // if no endpoint is given but api_keys are there, match the first api_key
167+ // with the default endpoint
166168 assert := assert .New (t )
167169 ddAgentConf , _ := ini .Load ([]byte ("[Main]\n \n api_key=foo,bar " ))
168170 configFile := & File {instance : ddAgentConf , Path : "whatever" }
169171 agentConfig , err := NewAgentConfig (configFile , nil )
170- assert .Error (err )
172+ assert .NoError (err )
173+ assert .Equal (1 , len (agentConfig .APIEndpoints ))
174+ assert .Equal ("foo" , agentConfig .APIEndpoints [0 ].APIKey )
175+ assert .Equal ("process.datadoghq.com" , agentConfig .APIEndpoints [0 ].Endpoint .Hostname ())
171176
172177 ddAgentConf , _ = ini .Load ([]byte (strings .Join ([]string {
173178 "[Main]" ,
174- "api_key = foo,bar" ,
179+ "api_key= foo,bar" ,
175180 "[process.config]" ,
176181 "endpoint=https://process.datadoghq.com,https://process.datadoghq.eu" ,
177182 }, "\n " )))
178183 configFile = & File {instance : ddAgentConf , Path : "whatever" }
179184 agentConfig , err = NewAgentConfig (configFile , nil )
185+ assert .NoError (err )
186+ assert .Equal (2 , len (agentConfig .APIEndpoints ))
180187 assert .Equal ("foo" , agentConfig .APIEndpoints [0 ].APIKey )
181188 assert .Equal ("process.datadoghq.com" , agentConfig .APIEndpoints [0 ].Endpoint .Hostname ())
182189 assert .Equal ("bar" , agentConfig .APIEndpoints [1 ].APIKey )
183190 assert .Equal ("process.datadoghq.eu" , agentConfig .APIEndpoints [1 ].Endpoint .Hostname ())
191+
192+ // if endpoint count is greater than api_key count, drop additional endpoints
193+ ddAgentConf , _ = ini .Load ([]byte (strings .Join ([]string {
194+ "[Main]" ,
195+ "api_key=foo" ,
196+ "[process.config]" ,
197+ "endpoint=https://process.datadoghq.com,https://process.datadoghq.eu" ,
198+ }, "\n " )))
199+ configFile = & File {instance : ddAgentConf , Path : "whatever" }
200+ agentConfig , err = NewAgentConfig (configFile , nil )
201+ assert .NoError (err )
202+ assert .Equal (1 , len (agentConfig .APIEndpoints ))
203+ assert .Equal ("foo" , agentConfig .APIEndpoints [0 ].APIKey )
204+ assert .Equal ("process.datadoghq.com" , agentConfig .APIEndpoints [0 ].Endpoint .Hostname ())
184205}
185206
186207func TestDefaultConfig (t * testing.T ) {
0 commit comments