mzcompose.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. from dataclasses import dataclass
  10. from materialize.mzcompose.composition import Composition, WorkflowArgumentParser
  11. from materialize.mzcompose.services.materialized import Materialized
  12. from materialize.mzcompose.services.mcp import Mcp
  13. SERVICES = [Materialized(), Mcp()]
  14. @dataclass
  15. class TestCase:
  16. name: str
  17. materialized_options: list[str]
  18. materialized_image: str | None = None
  19. test_cases = [
  20. TestCase(
  21. name="mcp-server",
  22. materialized_options=[],
  23. ),
  24. ]
  25. def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
  26. parser.add_argument(
  27. "filter", nargs="?", default="", help="limit to test cases matching filter"
  28. )
  29. parser.add_argument(
  30. "-k", nargs="?", default=None, help="limit tests by keyword expressions"
  31. )
  32. parser.add_argument("-s", action="store_true", help="don't suppress output")
  33. args = parser.parse_args()
  34. for test_case in test_cases:
  35. if args.filter in test_case.name:
  36. print(f"> Running test case {test_case.name}")
  37. materialized = Materialized(
  38. options=test_case.materialized_options,
  39. image=test_case.materialized_image,
  40. volumes_extra=["secrets:/secrets"],
  41. default_replication_factor=1,
  42. additional_system_parameter_defaults={
  43. "default_cluster_replication_factor": "1"
  44. },
  45. )
  46. test_args = ["tests/"]
  47. if args.k:
  48. test_args.append(f"-k {args.k}")
  49. if args.s:
  50. test_args.append("-s")
  51. with c.test_case(test_case.name):
  52. with c.override(materialized):
  53. c.down()
  54. c.up("materialized")
  55. c.run(
  56. "mcp",
  57. "uv",
  58. "run",
  59. "pytest",
  60. *test_args,
  61. env_extra={
  62. "MZ_DSN": "postgres://materialize@materialized:6875/materialize",
  63. },
  64. )