diff --git a/.travis.yml b/.travis.yml index 0f32d06..b315d0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,16 +15,20 @@ env: version: jessie - distribution: debian version: stretch +tests: + - opensource + - template + - upload before_install: - 'sudo docker pull ${distribution}:${version}' - 'sudo docker build --no-cache --rm --file=tests/dockerfiles/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests' script: - container_id=$(mktemp) - 'sudo docker run --detach --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro --volume="${PWD}":/etc/ansible/roles/ansible-role-nginx:ro ${distribution}-${version}:ansible > "${container_id}"' - - 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/test.yml --syntax-check' - - 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/test.yml' + - 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${tests}.yml --syntax-check' + - 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${tests}.yml' - > - sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/test.yml + sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${tests}.yml | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) diff --git a/tests/files/http/default.conf b/tests/files/http/default.conf new file mode 100644 index 0000000..cb80625 --- /dev/null +++ b/tests/files/http/default.conf @@ -0,0 +1,44 @@ +server { + listen 8080; + server_name localhost; + + #charset koi8-r; + #access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} +} diff --git a/tests/files/nginx.conf b/tests/files/nginx.conf new file mode 100644 index 0000000..ba09f41 --- /dev/null +++ b/tests/files/nginx.conf @@ -0,0 +1,31 @@ +user nginx; +worker_processes 4; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + include /etc/nginx/conf.d/*.conf; +} diff --git a/tests/inventory b/tests/inventory deleted file mode 100644 index 2fbb50c..0000000 --- a/tests/inventory +++ /dev/null @@ -1 +0,0 @@ -localhost diff --git a/tests/test.yml b/tests/playbooks/nginx-opensource.yml similarity index 83% rename from tests/test.yml rename to tests/playbooks/nginx-opensource.yml index 42bba2c..25ce5e7 100644 --- a/tests/test.yml +++ b/tests/playbooks/nginx-opensource.yml @@ -1,5 +1,6 @@ --- - hosts: localhost + become: true remote_user: root roles: - ansible-role-nginx diff --git a/tests/playbooks/nginx-template.yml b/tests/playbooks/nginx-template.yml new file mode 100644 index 0000000..1c95862 --- /dev/null +++ b/tests/playbooks/nginx-template.yml @@ -0,0 +1,10 @@ +--- +- hosts: localhost + become: true + remote_user: root + roles: + - ansible-role-nginx + vars: + http_template_enable: true + http_template_keepalive_timeout: 70 + http_template_listen: 82 diff --git a/tests/playbooks/nginx-upload.yml b/tests/playbooks/nginx-upload.yml new file mode 100644 index 0000000..66db643 --- /dev/null +++ b/tests/playbooks/nginx-upload.yml @@ -0,0 +1,11 @@ +--- +- hosts: localhost + become: true + remote_user: root + roles: + - ansible-role-nginx + vars: + main_push_enable: true + main_push_location: ../files/nginx.conf + http_push_enable: false + http_push_location: ../files/http/*.conf