Refactor instantiating the REST API instance (NewRestAPI call)
We have a growing number of occurrences of the following code in our unit tests:
settings := RestAPISettings{}
fa := agentcommtest.NewFakeAgents(nil, nil)
fec := &storktest.FakeEventCenter{}
rapi, err := NewRestAPI(&settings, dbSettings, db, fa, fec, nil)
We avoid globals, so we have to pass all instances that the RestAPI implementation may possibly need. With #461 (closed), I had to add new instance responsible for dispatching the configuration reviews. I followed the current pattern and simply added a new parameter to the NewRestAPI
call. It resulted in a tedious work to find all occurrences of this call and extend them with this new parameter. There are tons of them and the number is growing as we add new REST calls. I propose that we stabilise the interface of this function and use a structure instead of the changing number of parameters. The tests should use some generic mechanism to create a test specific instance of this structure and all tests should use this mechanism. We could also consider adding an interface (with functions returning specific values) and make this interface common between NewRestAPI
and other similar functions like NewStatePuller
which also needs to hold similar parameters.
Overall, the current way of passing parameters to the REST API instance seems unmaintainable in a long run.