Skip to content

Commit

Permalink
Replace bats test by Serverspec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zuazo committed Sep 19, 2015
1 parent 8cca6f9 commit 491d5c0
Show file tree
Hide file tree
Showing 38 changed files with 1,250 additions and 141 deletions.
11 changes: 0 additions & 11 deletions test/integration/mysql/bats/cron.bats

This file was deleted.

17 changes: 0 additions & 17 deletions test/integration/mysql/bats/default.bats

This file was deleted.

13 changes: 0 additions & 13 deletions test/integration/mysql/bats/mail.bats

This file was deleted.

9 changes: 9 additions & 0 deletions test/integration/mysql/serverspec/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# encoding: UTF-8
# -*- mode: ruby -*-
# vi: set ft=ruby :

source 'https://rubygems.org'

gem 'serverspec', '~> 2.0'
gem 'infrataster', '~> 0.3.0'
gem 'infrataster-plugin-mysql', '~> 0.2.0'
58 changes: 58 additions & 0 deletions test/integration/mysql/serverspec/apache_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# encoding: UTF-8
#
# Author:: Xabier de Zuazo (<xabier@zuazo.org>)
# Copyright:: Copyright (c) 2015 Xabier de Zuazo
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require_relative 'spec_helper'

family = os[:family].downcase
apache =
if %w(centos redhat fedora scientific amazon).include?(family)
'httpd'
else
'apache2'
end

describe 'apache' do
describe package(apache) do
it { should be_installed }
end

describe port(80) do
it { should be_listening }
end

describe port(443) do
it { should be_listening }
end

describe process(apache) do
it { should be_running }
end

describe process('nginx') do
it { should_not be_running }
end

describe server(:web) do
describe http('/') do
it 'runs Apache httpd' do
expect(response['Server']).to include 'Apache'
end
end # http /login.php
end # server web
end # apache
44 changes: 44 additions & 0 deletions test/integration/mysql/serverspec/cron_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# encoding: UTF-8
#
# Author:: Xabier de Zuazo (<xabier@zuazo.org>)
# Copyright:: Copyright (c) 2015 Xabier de Zuazo
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require_relative 'spec_helper'

family = os[:family].downcase

web_user =
case family
when 'debian', 'ubuntu'
'www-data'
when 'redhat', 'centos', 'fedora', 'scientific', 'amazon'
'apache'
when 'suse', 'opensuse'
'wwwrun'
when 'arch'
'http'
when 'freebsd'
'www'
else
'www-data'
end

describe 'owncloud cron' do
describe command("crontab -l -u #{web_user}") do
its(:stdout) { should match %r{php -f '.*/owncloud/cron.php'} }
end
end # owncloud cron
41 changes: 41 additions & 0 deletions test/integration/mysql/serverspec/mail_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# encoding: UTF-8
#
# Author:: Xabier de Zuazo (<xabier@zuazo.org>)
# Copyright:: Copyright (c) 2015 Xabier de Zuazo
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require_relative 'spec_helper'

describe 'owncloud email test' do
describe server(:web) do
describe http('http://127.0.0.1/emailtest.php') do
it 'returns OK status' do
expect(response.status).to eq 200
end

it 'sends an email' do
sleep(1)
spool_file =
if ::File.exist?('/var/spool/mail/root')
'/var/spool/mail/root'
else
'/var/spool/mail/vagrant'
end
expect(file(spool_file).content).to contain('kitchen-test@')
end
end # http /emailtest.php
end # server web
end # owncloud
40 changes: 40 additions & 0 deletions test/integration/mysql/serverspec/mysql_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# encoding: UTF-8
#
# Author:: Xabier de Zuazo (<xabier@zuazo.org>)
# Copyright:: Copyright (c) 2015 Xabier de Zuazo
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require_relative 'spec_helper'
require 'json'

describe 'mysql' do
describe process('mysqld') do
it { should be_running }
end

describe port(3306) do
it { should be_listening.with('tcp') }
end

describe server(:db) do
describe mysql_query('SHOW DATABASES') do
it 'includes `ownloud` database' do
databases = results.map { |r| r['Database'] }
expect(databases).to include('owncloud')
end
end
end # server db
end # mysql
68 changes: 68 additions & 0 deletions test/integration/mysql/serverspec/owncloud_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# encoding: UTF-8
#
# Author:: Xabier de Zuazo (<xabier@zuazo.org>)
# Copyright:: Copyright (c) 2015 Xabier de Zuazo
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require_relative 'spec_helper'
require 'json'

describe 'owncloud' do
describe server(:web) do
describe http('http://127.0.0.1/') do
it 'returns ownCloud text' do
expect(response.body).to include('ownCloud')
end
end # http /

describe http('http://127.0.0.1/status.php') do
let(:body_json) { JSON.parse(response.body) }

it 'returns a JSON body' do
expect { body_json }.to_not raise_error
end

it 'is installed' do
expect(body_json['installed']).to eq(true)
end
end # http /status.php

describe http('https://127.0.0.1/', ssl: { verify: false }) do
it 'returns ownCloud text' do
expect(response.body).to include('ownCloud')
end
end # https /

describe http('http://127.0.0.1/ocs/v1.php/privatedata/getattribute') do
it 'returns 401 status' do
expect(response.status).to eq 401
end

it 'returns unauthorised message' do
expect(response.body).to include('<message>Unauthorised</message>')
end
end # https /ocs/v1.php/privatedata/getattribute unauthorised

describe http(
'http://127.0.0.1/ocs/v1.php/privatedata/getattribute',
basic_auth: %w(test test)
) do
it 'returns OK status' do
expect(response.body).to include('<status>ok</status>')
end
end # https /ocs/v1.php/privatedata/getattribute with basic auth
end # server web
end # owncloud
49 changes: 49 additions & 0 deletions test/integration/mysql/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# encoding: UTF-8
#
# Author:: Xabier de Zuazo (<xabier@zuazo.org>)
# Copyright:: Copyright (c) 2015 Xabier de Zuazo
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'serverspec'
require 'infrataster/rspec'
require 'infrataster-plugin-mysql'

# Set backend type
set :backend, :exec

ENV['PATH'] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

Infrataster::Server.define(:web, '127.0.0.1')

Infrataster::Server.define(
:db,
'127.0.0.1',
mysql: { user: 'root', password: 'vagrant_root' }
)

# Infrataster hack to ignore phantomjs SSL errors
Infrataster::Contexts::CapybaraContext.class_eval do
def self.prepare_session
driver = Infrataster::Contexts::CapybaraContext::CAPYBARA_DRIVER_NAME
Capybara.register_driver driver do |app|
Capybara::Poltergeist::Driver.new(
app,
phantomjs_options: %w(--ignore-ssl-errors=true)
)
end
Capybara::Session.new(driver)
end
end
17 changes: 0 additions & 17 deletions test/integration/nginx/bats/default.bats

This file was deleted.

9 changes: 9 additions & 0 deletions test/integration/nginx/serverspec/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# encoding: UTF-8
# -*- mode: ruby -*-
# vi: set ft=ruby :

source 'https://rubygems.org'

gem 'serverspec', '~> 2.0'
gem 'infrataster', '~> 0.3.0'
gem 'infrataster-plugin-mysql', '~> 0.2.0'
Loading

0 comments on commit 491d5c0

Please sign in to comment.