Sylvain Desbureaux | 1d061a4 | 2019-11-08 15:27:20 +0100 | [diff] [blame] | 1 | --- |
| 2 | suite: test configmap behavior |
| 3 | templates: |
| 4 | - configmap.yaml |
| 5 | tests: |
| 6 | - it: "should render with default value" |
| 7 | asserts: |
| 8 | - isKind: |
| 9 | of: ConfigMap |
| 10 | - equal: |
| 11 | path: metadata.name |
| 12 | value: RELEASE-NAME-mariadb-init |
| 13 | - equal: |
| 14 | path: metadata.namespace |
| 15 | value: NAMESPACE |
| 16 | - matchRegex: |
| 17 | path: metadata.labels.app |
| 18 | pattern: mariadb-init |
| 19 | - equal: |
| 20 | path: data |
| 21 | value: |
| 22 | db_init.sh: | |
| 23 | #!/bin/sh |
| 24 | # Copyright © 2019 Orange |
| 25 | # |
| 26 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 27 | # you may not use this file except in compliance with the License. |
| 28 | # You may obtain a copy of the License at |
| 29 | # |
| 30 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 31 | # |
| 32 | # Unless required by applicable law or agreed to in writing, software |
| 33 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 34 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 35 | # See the License for the specific language governing permissions and |
| 36 | # limitations under the License. |
| 37 | |
| 38 | echo "Creating database ynsaUCru6mUNwGal and user u5WZ1GMSIS1wHZF..." |
| 39 | |
| 40 | mysql -h ${DB_HOST} -P ${DB_PORT} -uroot -p$MYSQL_ROOT_PASSWORD << 'EOF' || exit 1 |
| 41 | CREATE OR REPLACE USER 'u5WZ1GMSIS1wHZF'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}'; |
| 42 | CREATE OR REPLACE USER 'u5WZ1GMSIS1wHZF'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}'; |
| 43 | CREATE DATABASE IF NOT EXISTS ynsaUCru6mUNwGal; |
| 44 | GRANT ALL PRIVILEGES ON ynsaUCru6mUNwGal.* TO 'u5WZ1GMSIS1wHZF'@'%'; |
| 45 | GRANT ALL PRIVILEGES ON ynsaUCru6mUNwGal.* TO 'u5WZ1GMSIS1wHZF'@'localhost'; |
| 46 | EOF |
| 47 | |
| 48 | echo "Created database ynsaUCru6mUNwGal and user u5WZ1GMSIS1wHZF." |
| 49 | - it: "shoud render with other databases" |
| 50 | set: |
| 51 | config: |
| 52 | userName: testUser |
| 53 | mysqlDatabase: testDB |
| 54 | mysqlAdditionalDatabases: |
| 55 | dbOne: |
| 56 | user: one |
| 57 | password: pwd1 |
| 58 | dbTwo: |
| 59 | user: two |
| 60 | password: pwd2 |
| 61 | asserts: |
| 62 | - equal: |
| 63 | path: data |
| 64 | value: |
| 65 | db_init.sh: | |
| 66 | #!/bin/sh |
| 67 | # Copyright © 2019 Orange |
| 68 | # |
| 69 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 70 | # you may not use this file except in compliance with the License. |
| 71 | # You may obtain a copy of the License at |
| 72 | # |
| 73 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 74 | # |
| 75 | # Unless required by applicable law or agreed to in writing, software |
| 76 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 77 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 78 | # See the License for the specific language governing permissions and |
| 79 | # limitations under the License. |
| 80 | |
| 81 | echo "Creating database testDB and user testUser..." |
| 82 | |
| 83 | mysql -h ${DB_HOST} -P ${DB_PORT} -uroot -p$MYSQL_ROOT_PASSWORD << 'EOF' || exit 1 |
| 84 | CREATE OR REPLACE USER 'testUser'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}'; |
| 85 | CREATE OR REPLACE USER 'testUser'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}'; |
| 86 | CREATE DATABASE IF NOT EXISTS testDB; |
| 87 | GRANT ALL PRIVILEGES ON testDB.* TO 'testUser'@'%'; |
| 88 | GRANT ALL PRIVILEGES ON testDB.* TO 'testUser'@'localhost'; |
| 89 | EOF |
| 90 | |
| 91 | echo "Created database testDB and user testUser." |
| 92 | |
| 93 | echo "Creating database dbOne and user one..." |
| 94 | |
| 95 | mysql -h ${DB_HOST} -P ${DB_PORT} -uroot -p$MYSQL_ROOT_PASSWORD << 'EOF' || exit 1 |
| 96 | CREATE OR REPLACE USER 'one'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD_DBONE}'; |
| 97 | CREATE OR REPLACE USER 'one'@'%' IDENTIFIED BY '${MYSQL_PASSWORD_DBONE}'; |
| 98 | CREATE DATABASE IF NOT EXISTS dbOne; |
| 99 | GRANT ALL PRIVILEGES ON dbOne.* TO 'one'@'%'; |
| 100 | GRANT ALL PRIVILEGES ON dbOne.* TO 'one'@'localhost'; |
| 101 | EOF |
| 102 | |
| 103 | echo "Created database dbOne and user one." |
| 104 | echo "Creating database dbTwo and user two..." |
| 105 | |
| 106 | mysql -h ${DB_HOST} -P ${DB_PORT} -uroot -p$MYSQL_ROOT_PASSWORD << 'EOF' || exit 1 |
| 107 | CREATE OR REPLACE USER 'two'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD_DBTWO}'; |
| 108 | CREATE OR REPLACE USER 'two'@'%' IDENTIFIED BY '${MYSQL_PASSWORD_DBTWO}'; |
| 109 | CREATE DATABASE IF NOT EXISTS dbTwo; |
| 110 | GRANT ALL PRIVILEGES ON dbTwo.* TO 'two'@'%'; |
| 111 | GRANT ALL PRIVILEGES ON dbTwo.* TO 'two'@'localhost'; |
| 112 | EOF |
| 113 | |
| 114 | echo "Created database dbTwo and user two." |