| 1 |
#################################################################### |
| 2 |
# WARNING: These are designed specifically for Ansible tests # |
| 3 |
# and should not be used as examples of how to write Ansible roles # |
| 4 |
#################################################################### |
| 5 |
|
| 6 |
- name: Just run something |
| 7 |
register: result |
| 8 |
community.clickhouse.clickhouse_client: |
| 9 |
login_host: localhost |
| 10 |
client_kwargs: |
| 11 |
connect_timeout: 20 |
| 12 |
execute: SHOW DATABASES |
| 13 |
execute_kwargs: |
| 14 |
types_check: false |
| 15 |
|
| 16 |
- name: Check result |
| 17 |
ansible.builtin.assert: |
| 18 |
that: |
| 19 |
- result is changed |
| 20 |
- result.result != [] |
| 21 |
|
| 22 |
- name: Create dabase |
| 23 |
community.clickhouse.clickhouse_client: |
| 24 |
execute: CREATE DATABASE foo |
| 25 |
|
| 26 |
- name: Create user |
| 27 |
community.clickhouse.clickhouse_client: |
| 28 |
execute: "CREATE USER alice IDENTIFIED WITH sha256_password BY 'my_password'" |
| 29 |
|
| 30 |
- name: Query DB using non-default user & DB to connect to |
| 31 |
register: result |
| 32 |
community.clickhouse.clickhouse_client: |
| 33 |
execute: SELECT version() |
| 34 |
login_host: localhost |
| 35 |
login_user: alice |
| 36 |
login_db: foo |
| 37 |
login_password: my_password |
| 38 |
|
| 39 |
- name: Check result |
| 40 |
ansible.builtin.assert: |
| 41 |
that: |
| 42 |
- result.statistics["processed_rows"] == 1 |
| 43 |
|
| 44 |
- name: Create table |
| 45 |
register: result |
| 46 |
community.clickhouse.clickhouse_client: |
| 47 |
execute: CREATE TABLE test_table_1 (x String) ENGINE = Memory |
| 48 |
|
| 49 |
- name: Insert into test table using named args |
| 50 |
register: result |
| 51 |
community.clickhouse.clickhouse_client: |
| 52 |
execute: "INSERT INTO test_table_1 (x) VALUES (%(a)s), (%(b)s), (%(c)s)" |
| 53 |
execute_kwargs: |
| 54 |
params: |
| 55 |
a: one |
| 56 |
b: two |
| 57 |
c: three |
| 58 |
|
| 59 |
- name: Check the result |
| 60 |
ansible.builtin.assert: |
| 61 |
that: |
| 62 |
- result.substituted_query == "INSERT INTO test_table_1 (x) VALUES ('one'), ('two'), ('three')" |
| 63 |
- result.statistics["processed_rows"] == 3 |
| 64 |
|
| 65 |
- name: Check rows were inserted into test table |
| 66 |
register: result |
| 67 |
community.clickhouse.clickhouse_client: |
| 68 |
execute: "SELECT * FROM test_table_1" |
| 69 |
|
| 70 |
- name: Check the result |
| 71 |
ansible.builtin.assert: |
| 72 |
that: |
| 73 |
- result.result == [["one"], ["two"], ["three"]] |
| 74 |
|
| 75 |
# https://github.com/ansible-collections/community.clickhouse/pull/63/ |
| 76 |
- name: Load a schema with nested fields |
| 77 |
community.clickhouse.clickhouse_client: |
| 78 |
set_settings: |
| 79 |
flatten_nested: 0 |
| 80 |
execute: "CREATE TABLE foo.nested (`coordinates` Nested(x int, y int )) ENGINE = Memory" |
| 81 |
|
| 82 |
- name: Load nested data |
| 83 |
community.clickhouse.clickhouse_client: |
| 84 |
execute: "INSERT INTO foo.nested (coordinates) VALUES (([(10,20), (11,21)]))" |
| 85 |
|
| 86 |
- name: Read nested data |
| 87 |
register: nested_result |
| 88 |
community.clickhouse.clickhouse_client: |
| 89 |
execute: 'select * from foo.nested;' |
| 90 |
|
| 91 |
- name: Check nested data exists |
| 92 |
ansible.builtin.assert: |
| 93 |
that: |
| 94 |
- nested_result.result[0][0][0][0] == 10 |
| 95 |
- nested_result.result[0][0][0][1] == 20 |
| 96 |
- nested_result.result[0][0][1][0] == 11 |
| 97 |
- nested_result.result[0][0][1][1] == 21 |
| 98 |
|
| 99 |
|
| 100 |
- name: Check that the settings are applied |
| 101 |
register: result |
| 102 |
community.clickhouse.clickhouse_client: |
| 103 |
set_settings: |
| 104 |
flatten_nested: 0 |
| 105 |
execute: "SELECT value, changed FROM system.settings WHERE name='flatten_nested'" |
| 106 |
|
| 107 |
- name: Check result |
| 108 |
ansible.builtin.assert: |
| 109 |
that: |
| 110 |
- result.result[0][0] == "0" |
| 111 |
- result.result[0][1] == 1 |
| 112 |
|
| 113 |
# https://github.com/ansible-collections/community.clickhouse/issues/116 |
| 114 |
- name: Create a user |
| 115 |
community.clickhouse.clickhouse_user: |
| 116 |
state: present |
| 117 |
name: test_user1 |
| 118 |
password: querty |
| 119 |
|
| 120 |
- name: Grant all privs to the user |
| 121 |
register: result |
| 122 |
community.clickhouse.clickhouse_client: |
| 123 |
execute: 'GRANT ALL ON *.* TO test_user1 WITH GRANT OPTION' |
| 124 |
|
| 125 |
- name: Check the tast succeeded |
| 126 |
ansible.builtin.assert: |
| 127 |
that: |
| 128 |
- result is succeeded |