mzcompose.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. """
  10. Basic test for mz-debug
  11. """
  12. import subprocess
  13. from dataclasses import dataclass
  14. from materialize import spawn
  15. from materialize.mzcompose.composition import Composition, WorkflowArgumentParser
  16. from materialize.mzcompose.services.materialized import Materialized
  17. from materialize.mzcompose.services.mz_debug import MzDebug
  18. SERVICES = [
  19. Materialized(
  20. ports=[
  21. "6875:6875",
  22. "6877:6877",
  23. ]
  24. ),
  25. MzDebug(),
  26. ]
  27. @dataclass
  28. class TestCase:
  29. name: str
  30. dbt_env: dict[str, str]
  31. materialized_options: list[str]
  32. materialized_image: str | None = None
  33. test_cases = [
  34. TestCase(
  35. name="no-tls-cloud",
  36. materialized_options=[],
  37. dbt_env={},
  38. ),
  39. ]
  40. def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
  41. c.up("materialized")
  42. mz_debug = c.compose["services"]["mz-debug"]
  43. subprocess.run(
  44. ["docker", "pull", mz_debug["image"]],
  45. check=True,
  46. capture_output=True,
  47. )
  48. container_id = subprocess.check_output(
  49. ["docker", "create", mz_debug["image"]], text=True
  50. ).strip()
  51. subprocess.run(
  52. [
  53. "docker",
  54. "cp",
  55. f"{container_id}:/usr/local/bin/mz-debug",
  56. ".",
  57. ],
  58. check=True,
  59. )
  60. container_id = c.container_id("materialized")
  61. if container_id is None:
  62. raise ValueError("Failed to get materialized container ID")
  63. spawn.runv(
  64. [
  65. "./mz-debug",
  66. "emulator",
  67. "--docker-container-id",
  68. container_id,
  69. "--mz-connection-url",
  70. "postgres://mz_system@localhost:6877/materialize",
  71. ]
  72. )