apache/cloudstack-go

Decouple test configuration and enable running tests against a real backend

Opened this issue · 1 comments

Currently, in the test set the test configuration is (partly?) hardcoded using endpoint mocking approach with httptest:

func TestVirtualMachineService_DeployVirtualMachine(t *testing.T) {
	server := httptest.NewServer( ...

It would be great to have some decoupling here to provision endpoint configurations in a flexible way, also enabling automated testing against (multiple) real endpoints.

Hi @synergiator with the addition of #32, a change in https://github.com/apache/cloudstack-go/blob/main/test/cloudstack_test.go#L39 to return a server with the URL of a management server can be made. Eg:

func CreateTestServer(t *testing.T, responses map[string]json.RawMessage) *httptest.Server {
	return &httptest.Server{
		URL:      "http://server-ip:8080/client/api",
		Listener: &net.TCPListener{},
		Config:   &http.Server{},
	}
}

There will be other changes required such as passing optional or mutually exclusive parameters, and using an async client as needed

The main intent of the tests is to ensure that the json responses are successfully unmarshalled into the respective go structs