Skip to content

Commit 502667b

Browse files
committed
tests: Introduce doc example tests
1 parent 26827bf commit 502667b

39 files changed

+764
-64
lines changed

ci/test/pipeline.template.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,18 @@ steps:
722722
coverage: skip
723723
sanitizer: skip
724724

725+
- id: doc-examples
726+
label: Documentation Examples Code
727+
inputs:
728+
- doc/user/data/examples
729+
depends_on: build-aarch64
730+
timeout_in_minutes: 30
731+
plugins:
732+
- ./ci/plugins/mzcompose:
733+
composition: doc-examples
734+
agents:
735+
queue: hetzner-aarch64-4cpu-8gb
736+
725737
- id: deploy-website
726738
label: Deploy website
727739
depends_on: lint-docs

doc/user/data/examples/alter_sink.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
That is, assume you have a Kafka sink `avro_sink` created from `matview_old`
88
(See [`CREATE SINK`:Kafka/Redpanda](/sql/create-sink/kafka/) for more
99
information):
10+
test_setup: |
11+
> CREATE MATERIALIZED VIEW matview_old AS SELECT DISTINCT ON (key_col) 1 AS key_col;
12+
> CREATE CONNECTION kafka_connection TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
13+
> CREATE CONNECTION csr_connection TO CONFLUENT SCHEMA REGISTRY (URL '${testdrive.schema-registry-url}');
1014
code: |
1115
CREATE SINK avro_sink
1216
FROM matview_old
@@ -29,6 +33,8 @@
2933
to make progress. See [Valid schema changes](#valid-schema-changes) for
3034
details.
3135
{{< /note >}}
36+
test_setup: |
37+
> CREATE MATERIALIZED VIEW matview_new AS SELECT DISTINCT ON (key_col) 2 AS key_col;
3238
code: |
3339
ALTER SINK avro_sink
3440
SET FROM matview_new
@@ -48,6 +54,8 @@
4854
For workaround, see [Example: Handle cutover scenarios](#handle-cutover-scenarios)
4955
{{< /tip >}}
5056
57+
testable_results: false
58+
5159
- name: "handle-cutover-scenarios-intro"
5260
description: |
5361
Because Materialize emits updates from the newly specified relation **only** if
@@ -91,6 +99,7 @@
9199
- name: "handle-cutover-scenarios-alter-sink-to-transition"
92100
code: |
93101
ALTER SINK avro_sink SET FROM transition;
102+
testable: false # TODO: Materialize could not prove that the specified upsert envelope key ("key_col") was a unique key of the underlying relation "materialize.public.transition". There are no known valid unique keys for the underlying relation.
94103

95104
- name: "handle-cutover-scenarios-step-3-intro"
96105
description: |

doc/user/data/examples/create_source/example_postgres_source.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
PostgreSQL publication is `mz_source` and the connection to PostgreSQL is
2020
`pg_connection`.
2121
22+
test_setup: |
23+
> CREATE SECRET pgpass AS 'postgres'
24+
> CREATE CONNECTION pg_connection TO POSTGRES(HOST postgres, DATABASE postgres, USER postgres, PASSWORD SECRET pgpass);
25+
$ postgres-execute connection=postgres://postgres:postgres@postgres
26+
ALTER USER postgres WITH replication;
27+
DROP SCHEMA IF EXISTS public CASCADE;
28+
DROP PUBLICATION IF EXISTS mz_source;
29+
CREATE SCHEMA PUBLIC;
30+
CREATE TABLE items (a INT);
31+
ALTER TABLE items REPLICA IDENTITY FULL;
32+
CREATE PUBLICATION mz_source FOR ALL TABLES;
33+
2234
code: |
2335
/* This example assumes:
2436
- In the upstream PostgreSQL, you have defined:
@@ -62,3 +74,5 @@
6274
{{< /note >}}
6375
6476
For more information, see [`CREATE TABLE`](/sql/create-table/).
77+
78+
testable_results: false

doc/user/data/examples/create_table/example_postgres_table.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@
4848
4949
{{< /note >}}
5050
51+
test_setup: |
52+
> CREATE SECRET pgpass AS 'postgres'
53+
> CREATE CONNECTION pg_connection TO POSTGRES(HOST postgres, DATABASE postgres, USER postgres, PASSWORD SECRET pgpass);
54+
$ postgres-execute connection=postgres://postgres:postgres@postgres
55+
ALTER USER postgres WITH replication;
56+
DROP SCHEMA IF EXISTS public CASCADE;
57+
DROP PUBLICATION IF EXISTS mz_source;
58+
CREATE SCHEMA PUBLIC;
59+
CREATE TABLE items (a INT);
60+
ALTER TABLE items REPLICA IDENTITY FULL;
61+
CREATE TABLE orders (a INT);
62+
ALTER TABLE orders REPLICA IDENTITY FULL;
63+
CREATE PUBLICATION mz_source FOR ALL TABLES;
64+
65+
> CREATE SOURCE pg_source FROM POSTGRES CONNECTION pg_connection (PUBLICATION 'mz_source');
66+
5167
code: |
5268
/* This example assumes:
5369
- In the upstream PostgreSQL, you have defined:
@@ -86,6 +102,9 @@
86102
file="shared-content/create-table-from-source-snapshotting.md" >}}
87103
88104
{{< include-md file="shared-content/create-table-if-not-exists-tip.md" >}}
105+
106+
testable_results: false
107+
89108
- name: "show-tables"
90109
description: |
91110
To verify that the table has been created, you can run [`SHOW
@@ -116,6 +135,9 @@
116135
117136
For the list of supported PostgreSQL data types, refer to [supported
118137
types](/sql/create-table/postgres/#supported-data-types).
138+
test_results:
139+
- a true integer ""
140+
- a true integer ""
119141

120142
- name: "read-from-table"
121143
description: |

doc/user/data/examples/ingest_data/mysql/create_source_cloud.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
Once you have created the connection, you can use the connection in the
44
[`CREATE SOURCE`](/sql/create-source/) command to connect to your MySQL instance and start ingesting
55
data:
6+
test_setup: |
7+
> CREATE SECRET IF NOT EXISTS mysqlpass AS 'p@ssw0rd'
8+
> CREATE CONNECTION IF NOT EXISTS mysql_connection TO MYSQL (HOST mysql, USER root, PASSWORD SECRET mysqlpass)
9+
10+
$ mysql-connect name=mysql url=mysql://root@mysql password=p@ssw0rd
11+
$ mysql-execute name=mysql
12+
DROP DATABASE IF EXISTS public;
13+
CREATE DATABASE public;
14+
USE public;
15+
CREATE TABLE t (x INT);
16+
617
code: |
718
CREATE SOURCE mz_source
819
FROM MYSQL CONNECTION mysql_connection

doc/user/data/examples/ingest_data/postgres/create_connection_ips_cloud.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,38 @@
88
99
code: |
1010
CREATE SECRET pgpass AS '<PASSWORD>';
11+
test_replacements:
12+
<PASSWORD>: postgres
1113

1214
- name: "create-connection"
1315
description: |
1416
Use the [`CREATE CONNECTION`](/sql/create-connection/) command to create a
1517
connection object with access and authentication details for Materialize to
1618
use:
1719
20+
test_setup: |
21+
$ postgres-execute connection=postgres://postgres:postgres@postgres
22+
DROP USER IF EXISTS materialize;
23+
CREATE USER materialize WITH SUPERUSER PASSWORD 'postgres';
24+
ALTER USER materialize WITH replication;
25+
DROP SCHEMA IF EXISTS public CASCADE;
26+
DROP PUBLICATION IF EXISTS mz_source;
27+
CREATE SCHEMA PUBLIC;
28+
CREATE TABLE items (a INT);
29+
ALTER TABLE items REPLICA IDENTITY FULL;
30+
CREATE PUBLICATION mz_source FOR ALL TABLES;
1831
code: |
1932
CREATE CONNECTION pg_connection TO POSTGRES (
2033
HOST '<host>',
2134
PORT 5432,
22-
USER 'materialize',
35+
USER materialize,
2336
PASSWORD SECRET pgpass,
2437
SSL MODE 'require',
2538
DATABASE '<database>'
2639
);
40+
test_replacements:
41+
<host>: postgres
42+
<database>: postgres
2743

2844
- name: "create-connection-options-general"
2945
description: |

doc/user/data/examples/ingest_data/postgres/create_connection_privatelink_cloud.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
client connected to Materialize, use the [`CREATE
55
CONNECTION`](/sql/create-connection/#aws-privatelink) command to create an
66
AWS PrivateLink connection:
7+
test_setup: |
8+
$ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
9+
ALTER SYSTEM SET max_aws_privatelink_connections = 5
710
code: |
811
CREATE CONNECTION privatelink_svc TO AWS PRIVATELINK (
912
SERVICE NAME 'com.amazonaws.vpce.us-east-1.vpce-svc-0356210a8a432d9e9',
1013
AVAILABILITY ZONES ('use1-az1', 'use1-az2', 'use1-az4')
1114
);
15+
testable: false # TODO: Reenable when database-issues#9932 is fixed
1216
- name: "create-privatelink-connection-options-aurora"
1317
description: |
1418
- Replace the `SERVICE NAME` value with the service name you noted
@@ -35,10 +39,13 @@
3539
To connect to an AWS PrivateLink endpoint service in the **same region** as
3640
your Materialize environment:
3741
42+
test_setup: |
43+
> DROP CONNECTION privatelink_svc
3844
code: |
3945
CREATE CONNECTION privatelink_svc TO AWS PRIVATELINK ( SERVICE
4046
NAME 'com.amazonaws.vpce.<region_id>.vpce-svc-<endpoint_service_id>',
4147
AVAILABILITY ZONES ('use1-az1', 'use1-az2', 'use1-az4') );
48+
testable: false # TODO: Reenable when database-issues#9932 is fixed
4249

4350
- name: "create-privatelink-connection-rds-in-region-options"
4451
description: |
@@ -60,11 +67,14 @@
6067
6168
To connect to an AWS PrivateLink endpoint service in a **different region**
6269
to the one where your Materialize environment is deployed:
70+
test_setup: |
71+
> DROP CONNECTION privatelink_svc
6372
code: |
6473
CREATE CONNECTION privatelink_svc TO AWS PRIVATELINK ( SERVICE
6574
NAME 'com.amazonaws.vpce.us-west-1.vpce-svc-<endpoint_service_id>', -- For
6675
now, the AVAILABILITY ZONES clause **is** required, but will be -- made
6776
optional in a future release. AVAILABILITY ZONES () );
77+
testable: false # TODO: Reenable when database-issues#9932 is fixed
6878

6979
- name: "create-privatelink-connection-rds-cross-region-options"
7080
description: |-
@@ -84,6 +94,7 @@
8494
FROM mz_aws_privatelink_connections plc
8595
JOIN mz_connections c ON plc.id = c.id
8696
WHERE c.name = 'privatelink_svc';
97+
testable: false # TODO: Reenable when database-issues#9932 is fixed
8798

8899

89100
- name: "get-principal-privatelink-connection-results"
@@ -117,6 +128,8 @@
117128
VALIDATE CONNECTION privatelink_svc;
118129
results: |
119130
If no validation error is returned, move to the next step.
131+
testable_results: false
132+
testable: false # TODO: Reenable when database-issues#9932 is fixed
120133

121134
- name: "create-secret"
122135
description: |
@@ -126,6 +139,7 @@
126139
127140
code: |
128141
CREATE SECRET pgpass AS '<PASSWORD>';
142+
testable: false # TODO: Reenable when database-issues#9932 is fixed
129143

130144
- name: "create-connection"
131145
description: |
@@ -142,6 +156,7 @@
142156
DATABASE '<database>',
143157
AWS PRIVATELINK privatelink_svc
144158
);
159+
testable: false # TODO: Reenable when database-issues#9932 is fixed
145160

146161
- name: "create-connection-options-aurora"
147162
description: |

doc/user/data/examples/ingest_data/postgres/create_connection_ssh_cloud.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
PORT <SSH_BASTION_PORT>,
1212
USER '<SSH_BASTION_USER>'
1313
);
14+
test_replacements:
15+
<SSH_BASTION_HOST>: ssh-bastion-host
16+
<SSH_BASTION_PORT>: 22
17+
<SSH_BASTION_USER>: mz
1418

1519
- name: "create-ssh-tunnel-connection-options"
1620
description: |-
@@ -24,8 +28,12 @@
2428
- name: "get-public-keys-general"
2529
description: |
2630
Get Materialize's public keys for the SSH tunnel connection:
31+
test_setup: |
32+
$ set-regex match=.* replacement=X
2733
code: |
2834
SELECT * FROM mz_ssh_tunnel_connections;
35+
test_results: |
36+
X X X
2937
3038
- name: "get-public-keys-aurora-rds-self-hosted"
3139
description: |
@@ -40,6 +48,8 @@
4048
mz_ssh_tunnel_connections USING(id)
4149
WHERE
4250
mz_connections.name = 'ssh_connection';
51+
test_results: |
52+
X X X X
4353
4454
- name: "login-to-ssh-bastion-host"
4555
description: |
@@ -49,17 +59,21 @@
4959
code: |
5060
echo "ssh-ed25519 AAAA...76RH materialize" >> ~/.ssh/authorized_keys
5161
echo "ssh-ed25519 AAAA...hLYV materialize" >> ~/.ssh/authorized_keys
62+
testable: false
5263

5364
- name: "validate-ssh-tunnel-connection"
5465
description: |
5566
Back in the SQL client connected to Materialize, validate the SSH tunnel
5667
connection you created using the [`VALIDATE
5768
CONNECTION`](/sql/validate-connection) command:
5869
70+
test_setup: |
71+
$ unset-regex
5972
code: |
6073
VALIDATE CONNECTION ssh_connection;
6174
results: |
6275
If no validation error is returned, move to the next step.
76+
testable_results: false
6377

6478
- name: "create-secret"
6579
description: |
@@ -69,12 +83,25 @@
6983
7084
code: |
7185
CREATE SECRET pgpass AS '<PASSWORD>';
86+
test_replacements:
87+
<PASSWORD>: postgres
7288

7389
- name: "create-connection"
7490
description: |
7591
7692
Use the [`CREATE CONNECTION`](/sql/create-connection/) command to create another connection object, this time with database access and authentication details for Materialize to use:
7793
94+
test_setup: |
95+
$ postgres-execute connection=postgres://postgres:postgres@postgres
96+
DROP USER IF EXISTS materialize;
97+
CREATE USER materialize WITH SUPERUSER PASSWORD 'postgres';
98+
ALTER USER materialize WITH replication;
99+
DROP SCHEMA IF EXISTS public CASCADE;
100+
DROP PUBLICATION IF EXISTS mz_source;
101+
CREATE SCHEMA PUBLIC;
102+
CREATE TABLE items (a INT);
103+
ALTER TABLE items REPLICA IDENTITY FULL;
104+
CREATE PUBLICATION mz_source FOR ALL TABLES;
78105
code: |
79106
CREATE CONNECTION pg_connection TO POSTGRES (
80107
HOST '<host>',
@@ -84,6 +111,9 @@
84111
DATABASE '<database>',
85112
SSH TUNNEL ssh_connection
86113
);
114+
test_replacements:
115+
<host>: postgres
116+
<database>: postgres
87117

88118
- name: "create-connection-options-general"
89119
description: |

0 commit comments

Comments
 (0)