Yes, this is feasible. I do something following this exact use case.
It seems like you are using docker.Keep in mind you have access to almost full docker capabilities when setting up your tests, by that I mean you can mount volumes, isolate networks, use a Dockerfile etc
platforms:
- name: client
image: ubuntu:focal
groups:
- clients
exposed_ports:
- 3022
published_ports:
- 0.0.0.0:3022:3022/tcp
networks:
- name: molecule_test
links:
- server
- name: server
image: ubuntu:focal
exposed_ports:
- 3080
- 443
- 3025
published_ports:
- 0.0.0.0:3025:3025/tcp
- 0.0.0.0:3080:3080/tcp
- 0.0.0.0:443:443/tcp
networks:
- name: molecule_test
links:
- client
groups:
- servers
Now in my case, I am only testing the client. However,I want to ensure the client is making calls to the server correctly. I do the following in my test_scenario.py file. This assumes you are using TestInfra
import testinfra
from testinfra.host import Host
testinfra_hosts = ["clients"]
def get_server() -> Host:
return testinfra.get_host("docker://root@server")
def test_client_server_interaction(host: Host):
client_name = "p3-10000"
server = get_server()
client_joined = server.run("client-manager nodes list")
assert client_name in client_joined.stdout
In this case, my host under test is "client", however, I want to make sure the "client" is calling "server" correctly.
I'll also mention you can/should use prepare.yml to setup servers/external dependencies. What goes in your prepare.yml can be wholly unrelated to your role under test
Examples of what you might put in your prepare.yml.
- Database servers - In this case you might setup a DB and tests client insert correct rows
- Mock Http Endpoints - Setup mock http servers and assert client use correct params/verbs etc
- Calling Cloud (AWS GCP) to setup resources