require 'spec_helper'

describe interface('br0') do
  it { should exist }
end

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

describe package('bridge-utils') do
  it { should be_installed }
end

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

describe file('/etc/openvpn/default') do
  it { should be_directory }
end

describe file('/etc/openvpn/default/keys') do
  it { should be_directory }
end

describe file('/var/log/openvpn') do
  it { should be_directory }
end

describe file('/etc/openvpn/default/keys/ca.crt') do
  it { should be_file }
end

describe file('/etc/openvpn/default/keys/dh.pem') do
  it { should be_file }
end

describe file('/etc/openvpn/default/keys/crl.pem') do
  it { should be_file }
end

describe file('/etc/openvpn/default/keys/server.crt') do
  it { should be_file }
end

describe file('/etc/openvpn/default/keys/server.key') do
  it { should be_file }
end

describe file('/etc/openvpn/default.conf') do
  it { should be_file }
  it { should contain 'Generated by Chef' }
  it { should contain 'port 1194' }
  it { should contain 'proto udp' }
  it { should contain 'dev tap' }
  it { should contain 'server-bridge 127.0.0.1 255.255.255.0 127.0.0.100 127.0.0.150' }
  it { should contain 'up "/etc/openvpn/up.sh br0 eth0"' }
  it { should contain 'down "/etc/openvpn/down.sh br0 eth0"' }
end

describe file('/etc/openvpn/up.sh') do
  it { should be_file }
end

describe file('/etc/openvpn/down.sh') do
  it { should be_file }
end

describe service('openvpn') do
  it { should be_enabled }
  it { should be_running }
end

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