add collections
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
azp/posix/1
|
||||
destructive
|
||||
skip/osx
|
||||
skip/macos
|
||||
skip/rhel8.0
|
||||
skip/rhel9.0
|
||||
skip/freebsd
|
||||
@@ -0,0 +1,38 @@
|
||||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# defaults file for test_postgresql_db
|
||||
my_user: 'ansible_user'
|
||||
my_pass: 'md5d5e044ccd9b4b8adc89e8fed2eb0db8a'
|
||||
my_pass_decrypted: '6EjMk<hcX3<5(Yp?Xi5aQ8eS`a#Ni'
|
||||
dsn: "DRIVER={PostgreSQL};Server=localhost;Port=5432;Database=postgres;Uid={{ my_user }};Pwd={{ my_pass_decrypted }};UseUnicode=True"
|
||||
packages:
|
||||
Alpine:
|
||||
- psqlodbc
|
||||
- unixodbc
|
||||
- unixodbc-dev
|
||||
- g++
|
||||
Archlinux:
|
||||
- unixodbc
|
||||
RedHat:
|
||||
- postgresql-odbc
|
||||
- unixODBC
|
||||
- unixODBC-devel
|
||||
- gcc
|
||||
- gcc-c++
|
||||
Debian:
|
||||
- odbc-postgresql
|
||||
- unixodbc
|
||||
- unixodbc-dev
|
||||
- gcc
|
||||
- g++
|
||||
Suse:
|
||||
- psqlODBC
|
||||
- unixODBC
|
||||
- unixODBC-devel
|
||||
- gcc
|
||||
- gcc-c++
|
||||
FreeBSD:
|
||||
- unixODBC
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
dependencies:
|
||||
- setup_pkg_mgr
|
||||
- setup_postgresql_db
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: "Install {{ ansible_os_family }} Libraries"
|
||||
package:
|
||||
name: "{{ packages[ansible_os_family] }}"
|
||||
|
||||
- name: "Install pyodbc"
|
||||
pip:
|
||||
name: pyodbc
|
||||
@@ -0,0 +1,158 @@
|
||||
---
|
||||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- when:
|
||||
- ansible_os_family != 'Archlinux' # TODO install driver from AUR: https://aur.archlinux.org/packages/psqlodbc
|
||||
block:
|
||||
|
||||
#
|
||||
# Test for proper failures without pyodbc
|
||||
#
|
||||
# Some of the docker images already have pyodbc installed on it
|
||||
- include_tasks: no_pyodbc.yml
|
||||
when: ansible_os_family != 'FreeBSD' and ansible_os_family != 'Suse' and ansible_os_family != 'Debian'
|
||||
|
||||
#
|
||||
# Get pyodbc installed
|
||||
#
|
||||
- include_tasks: install_pyodbc.yml
|
||||
|
||||
#
|
||||
# Test missing parameters & invalid DSN
|
||||
#
|
||||
- include_tasks: negative_tests.yml
|
||||
|
||||
#
|
||||
# Setup DSN per env
|
||||
#
|
||||
- name: Changing DSN for Suse
|
||||
set_fact:
|
||||
dsn: "DRIVER={PSQL};Server=localhost;Port=5432;Database=postgres;Uid={{ my_user }};Pwd={{ my_pass_decrypted }};UseUnicode=True"
|
||||
when: ansible_os_family == 'Suse' or ansible_os_family == 'Alpine'
|
||||
|
||||
- name: Changing DSN for Alpine
|
||||
set_fact:
|
||||
dsn: "DRIVER={/usr/lib/psqlodbcw.so};Server=localhost;Port=5432;Database=postgres;Uid={{ my_user }};Pwd={{ my_pass_decrypted }};UseUnicode=True"
|
||||
when: ansible_os_family == 'Alpine'
|
||||
|
||||
- name: Changing DSN for Debian
|
||||
set_fact:
|
||||
dsn: "DRIVER={PostgreSQL Unicode};Server=localhost;Port=5432;Database=postgres;Uid={{ my_user }};Pwd={{ my_pass_decrypted }};UseUnicode=True"
|
||||
when: ansible_os_family == 'Debian'
|
||||
|
||||
#
|
||||
# Name setup database
|
||||
#
|
||||
- name: Create a user to run the tests with
|
||||
shell: echo "CREATE USER {{ my_user }} SUPERUSER PASSWORD '{{ my_pass }}'" | psql postgres
|
||||
become_user: "{{ pg_user }}"
|
||||
become: True
|
||||
|
||||
- name: Create a table
|
||||
odbc:
|
||||
dsn: "{{ dsn }}"
|
||||
query: |
|
||||
CREATE TABLE films (
|
||||
code char(5) CONSTRAINT firstkey PRIMARY KEY,
|
||||
title varchar(40) NOT NULL,
|
||||
did integer NOT NULL,
|
||||
date_prod date,
|
||||
kind varchar(10),
|
||||
len interval hour to minute
|
||||
);
|
||||
become_user: "{{ pg_user }}"
|
||||
become: True
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- results is changed
|
||||
|
||||
#
|
||||
# Insert records
|
||||
#
|
||||
- name: Insert a record without params
|
||||
odbc:
|
||||
dsn: "{{ dsn }}"
|
||||
query: "INSERT INTO films (code, title, did, date_prod, kind, len) VALUES ('asdfg', 'My First Movie', 1, '2019-01-12', 'SyFi', '02:00')"
|
||||
become_user: "{{ pg_user }}"
|
||||
become: True
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- results is changed
|
||||
|
||||
- name: Insert a record with params
|
||||
odbc:
|
||||
dsn: "{{ dsn }}"
|
||||
query: "INSERT INTO films (code, title, did, date_prod, kind, len) VALUES (?, ?, ?, ?, ?, ?)"
|
||||
params:
|
||||
- 'qwert'
|
||||
- 'My Second Movie'
|
||||
- 2
|
||||
- '2019-01-12'
|
||||
- 'Comedy'
|
||||
- '01:30'
|
||||
become_user: "{{ pg_user }}"
|
||||
become: True
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- results is changed
|
||||
- results['row_count'] == -1
|
||||
- results['results'] == []
|
||||
- results['description'] == []
|
||||
|
||||
#
|
||||
# Select data
|
||||
#
|
||||
- name: Perform select single row without params (do not coherse changed)
|
||||
odbc:
|
||||
dsn: "{{ dsn }}"
|
||||
query: "SELECT * FROM films WHERE code='asdfg'"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- results is changed
|
||||
- results is successful
|
||||
- results.row_count == 1
|
||||
|
||||
- name: Perform select multiple rows with params (coherse changed)
|
||||
odbc:
|
||||
dsn: "{{ dsn }}"
|
||||
query: 'SELECT * FROM films WHERE code=? or code=?'
|
||||
params:
|
||||
- 'asdfg'
|
||||
- 'qwert'
|
||||
register: results
|
||||
changed_when: False
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- results is not changed
|
||||
- results is successful
|
||||
- results.row_count == 2
|
||||
|
||||
- name: Drop the table
|
||||
odbc:
|
||||
dsn: "{{ dsn }}"
|
||||
query: "DROP TABLE films"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- results is successful
|
||||
- results is changed
|
||||
- results['row_count'] == -1
|
||||
- results['results'] == []
|
||||
- results['description'] == []
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#
|
||||
# Missing params for the module
|
||||
# There is nothing you need to do here because the params are required
|
||||
#
|
||||
|
||||
#
|
||||
# Invalid DSN in the module
|
||||
#
|
||||
- name: "Test with an invalid DSN"
|
||||
odbc:
|
||||
dsn: "t1"
|
||||
query: "SELECT * FROM nothing"
|
||||
register: results
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- results is failed
|
||||
- "'Failed to connect to DSN' in results.msg"
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Testing the module without pyodbc
|
||||
odbc:
|
||||
dsn: "Test"
|
||||
query: "SELECT * FROM nothing"
|
||||
ignore_errors: True
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- results is failed
|
||||
- "'Failed to import the required Python library (pyodbc) on' in results.msg"
|
||||
Reference in New Issue
Block a user