Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added integration tests for Windows #346

Merged
merged 4 commits into from
Sep 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ platforms:
named_run_list: freebsd
- name: windows-2012r2
named_run_list: windows
driver_config:
network:
- ["forwarded_port", {guest: 3389, host: 3389}]
- ["forwarded_port", {guest: 5985, host: 5985}]
communicator: winrm
customize:
usbehci: "off"

suites:
- name: default
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/policies/_base.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
default_source :community
default_source :chef_repo, '..'
cookbook 'consul', path: '../../..'
run_list 'sudo::default', 'consul::default', "consul_spec::#{name}"
named_run_list :centos, 'yum::default', 'yum-centos::default', run_list
run_list 'consul::default', "consul_spec::#{name}"
named_run_list :centos, 'yum::default', 'yum-centos::default', 'sudo::default',run_list
named_run_list :debian, 'apt::default', run_list
named_run_list :freebsd, 'freebsd::default', run_list
named_run_list :freebsd, 'freebsd::default', 'sudo::default', run_list
named_run_list :windows, 'windows::default', run_list
106 changes: 64 additions & 42 deletions test/integration/default/serverspec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
require 'spec_helper'

consul_version = '0.7.0'
consul_executable = "/opt/consul/#{consul_version}/consul"

if windows?
consul_executable = "C:\\Program Files\\consul\\#{consul_version}\\consul.exe"
consul_command = "& '#{consul_executable}'"
else
consul_executable = "/opt/consul/#{consul_version}/consul"
consul_command = consul_executable
end

describe file(consul_executable) do
it { should be_file }
it { should be_executable }
it { should be_executable } unless windows?
end

describe group('consul') do
it { should exist }
end
unless windows?
describe group('consul') do
it { should exist }
end

describe user('consul') do
it { should exist }
it { should belong_to_group('consul') }
end
describe user('consul') do
it { should exist }
it { should belong_to_group('consul') }
end

describe command("su - consul -c 'echo successfully logged in'") do
its(:stdout) { should_not match /successfully logged in/ }
its(:exit_status) { should_not eq 0 }
describe command("su - consul -c 'echo successfully logged in'") do
its(:stdout) { should_not match /successfully logged in/ }
its(:exit_status) { should_not eq 0 }
end
end

describe service('consul') do
Expand All @@ -33,63 +42,76 @@
end
end

describe command('/opt/consul/0.7.0/consul members -detailed') do
describe command("#{consul_command} members -detailed") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match %r{\balive\b} }
its(:stdout) { should match %r{\brole=consul\b} }
its(:stdout) { should match %r{\bbootstrap=1\b} }
its(:stdout) { should match %r{\bdc=fortmeade\b} }
end

config_dir = '/etc/consul'
config_file = '/etc/consul/consul.json'
confd_dir = '/etc/consul/conf.d'
data_dir = '/var/lib/consul'
unless windows?
config_dir = '/etc/consul'

describe file(config_dir) do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'consul' }
describe file(config_dir) do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'consul' }
it { should be_mode 755 }
end
end

it { should be_mode 755 }
if windows?
config_file = 'C:\Program Files\consul\consul.json'
confd_dir = 'C:\Program Files\consul\conf.d'
data_dir = 'C:\Program Files\consul\data'
else
config_file = '/etc/consul/consul.json'
confd_dir = '/etc/consul/conf.d'
data_dir = '/var/lib/consul'
end

describe file(config_file) do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'consul' }

it { should be_mode 640 }
unless windows?
it { should be_owned_by 'root' }
it { should be_grouped_into 'consul' }
it { should be_mode 640 }
end
end

describe file(confd_dir) do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'consul' }

it { should be_mode 755 }
unless windows?
it { should be_owned_by 'root' }
it { should be_grouped_into 'consul' }
it { should be_mode 755 }
end
end

describe file(data_dir) do
it { should be_directory }
it { should be_owned_by 'consul' }
it { should be_grouped_into 'consul' }

it { should be_mode 750 }
unless windows?
it { should be_owned_by 'consul' }
it { should be_grouped_into 'consul' }
it { should be_mode 750 }
end
end

describe file("#{confd_dir}/consul_definition_check.json") do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'consul' }

it { should be_mode 640 }
unless windows?
it { should be_owned_by 'root' }
it { should be_grouped_into 'consul' }
it { should be_mode 640 }
end
end

describe file("#{confd_dir}/consul_watch_check.json") do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'consul' }

it { should be_mode 640 }
unless windows?
it { should be_owned_by 'root' }
it { should be_grouped_into 'consul' }
it { should be_mode 640 }
end
end
7 changes: 6 additions & 1 deletion test/integration/helpers/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
require 'serverspec'

if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil?
def windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end

if !windows?
set :backend, :exec
else
set :backend, :cmd
set :os, family: 'windows'
set :architecture, :x86_64
end

# Tells serverspec to use a login shell for running chkconfig/service,
Expand Down