def test_docker_wrapper_should_throw_runtime_error_when_ports_clash(): port = 4200 with pytest.raises(RuntimeError) as execinfo: with create_container("crate", ports={"4200/tcp": port}): with create_container("crate", ports={"4200/tcp": port}) as container2: assert container2.status == 'running' assert "500 Server Error" in str(execinfo.value)
def get_container_func(request): global CONNECTION_HOST image, historian_version = request.param print(f"image: {image} historian schema; version {historian_version}") if historian_version == "<4.0.0" and image.startswith("mysql:8"): pytest.skip( msg=f"Default schema of historian version <4.0.0 " f"will not work in mysql version > 5. Skipping tests " f"for this parameter combination ", allow_module_level=True, ) kwargs = {"env": ENV_MYSQL} if os.path.exists("/.dockerenv"): print("Running test within docker container.") connection_port = 3306 CONNECTION_HOST = "mysql_test" kwargs["hostname"] = CONNECTION_HOST else: ports_dict = ports_config() kwargs["ports"] = ports_dict["ports"] connection_port = ports_dict["port_on_host"] CONNECTION_HOST = "localhost" with create_container(request.param[0], **kwargs) as container: wait_for_connection(container) create_all_tables(container, historian_version) mysqlfuncts = get_mysqlfuncts(connection_port) sleep(5) # So that sqlfuncts class can check if metadata is in topics table and sets its variables accordingly mysqlfuncts.setup_historian_tables() yield container, mysqlfuncts, connection_port, historian_version
def test_docker_wrapper_should_throw_runtime_error_on_false_image_when_pull(): with pytest.raises(RuntimeError) as execinfo: with create_container("not_a_real_image", ports={"4200/tcp": 4200}) as container: container.logs() assert "404 Client Error" in str(execinfo.value)
def test_docker_wrapper(): with create_container("mysql", ports={"3306/tcp": 3306}, env={"MYSQL_ROOT_PASSWORD": "******"}) as container: print(f"\nStatus: {container.status}") print(f"\nLogs: {container.logs()}") assert container.status == 'running'
def get_container_func(request): global CONNECTION_HOST historian_version = request.param[1] kwargs = {'env': ENV_POSTGRESQL} if os.path.exists("/.dockerenv"): print("Running test within docker container.") connection_port = 5432 CONNECTION_HOST = 'postgresql_test' kwargs['hostname'] = CONNECTION_HOST else: ports_dict = ports_config() kwargs['ports'] = ports_dict["ports"] connection_port = ports_dict["port_on_host"] CONNECTION_HOST = 'localhost' with create_container(request.param[0], **kwargs) as container: wait_for_connection(container, connection_port) create_all_tables(container, historian_version) postgresfuncts = get_postgresqlfuncts(connection_port) postgresfuncts.setup_historian_tables() yield container, postgresfuncts, connection_port, historian_version
def test_docker_run_crate_latest(): with create_container("crate", ports={"4200/tcp": 4200}) as container: assert container.status == 'running'