Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple test configuration and enable running tests against a real backend #28

Open
synergiator opened this issue Dec 27, 2021 · 1 comment
Assignees

Comments

@synergiator
Copy link

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.

@davidjumani
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants