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

Mirror url custom port #121

Merged
merged 15 commits into from
Dec 26, 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
2 changes: 1 addition & 1 deletion manifests/broker.pp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
) inherits kafka::params {

validate_re($::osfamily, 'RedHat|Debian\b', "${::operatingsystem} not supported")
validate_re($mirror_url, '^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})(:[\d]{2,5})?([\/\w \.-]*)*\/?$', "${mirror_url} is not a valid url")
validate_re($mirror_url, $kafka::params::mirror_url_regex, "${mirror_url} is not a valid url")
validate_hash($config)
validate_bool($install_java)
validate_absolute_path($package_dir)
Expand Down
2 changes: 1 addition & 1 deletion manifests/consumer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
) inherits kafka::params {

validate_re($::osfamily, 'RedHat|Debian\b', "${::operatingsystem} not supported")
validate_re($mirror_url, '^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$', "${mirror_url} is not a valid url")
validate_re($mirror_url, $kafka::params::mirror_url_regex, "${mirror_url} is not a valid url")
validate_bool($install_java)
validate_absolute_path($package_dir)
validate_bool($service_restart)
Expand Down
2 changes: 1 addition & 1 deletion manifests/mirror.pp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
) inherits kafka::params {

validate_re($::osfamily, 'RedHat|Debian\b', "${::operatingsystem} not supported")
validate_re($mirror_url, '^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$', "${mirror_url} is not a valid url")
validate_re($mirror_url, $kafka::params::mirror_url_regex, "${mirror_url} is not a valid url")
validate_integer($num_streams)
validate_integer($num_producers)
validate_bool($abort_on_send_failure)
Expand Down
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,6 @@
'topic' => '',
'value-serializer' => 'kafka.serializer.DefaultEncoder',
}

$mirror_url_regex = '^(https?:\/\/)([\da-z\.-]+)\.([a-z\.]{2,6})(:[\d]{2,5})?(\/[\w \.-]*)*\/?$'
}
2 changes: 1 addition & 1 deletion manifests/producer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
) inherits kafka::params {

validate_re($::osfamily, 'RedHat|Debian\b', "${::operatingsystem} not supported")
validate_re($mirror_url, '^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$', "${mirror_url} is not a valid url")
validate_re($mirror_url, $kafka::params::mirror_url_regex, "${mirror_url} is not a valid url")
validate_bool($install_java)
validate_absolute_path($package_dir)
validate_bool($service_restart)
Expand Down
23 changes: 10 additions & 13 deletions spec/classes/broker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'shared_examples_param_validation'

describe 'kafka::broker', type: :class do
let :facts do
Expand All @@ -11,14 +12,18 @@
service_provider: 'upstart'
}
end
let :params do
let :common_params do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{
config: {
'zookeeper.connect' => 'localhost:2181'
}
}
end

let :params do
common_params
end

it { is_expected.to contain_class('kafka::broker::install').that_comes_before('Class[kafka::broker::config]') }
it { is_expected.to contain_class('kafka::broker::config').that_comes_before('Class[kafka::broker::service]') }
it { is_expected.to contain_class('kafka::broker::service').that_comes_before('Class[kafka::broker]') }
Expand All @@ -40,12 +45,7 @@
describe 'kafka::broker::service' do
context 'service_install false' do
let :params do
{
config: {
'zookeeper.connect' => 'localhost:2181'
},
service_install: false
}
common_params.merge(service_install: false)
end
it { is_expected.not_to contain_file('kafka.service') }

Expand Down Expand Up @@ -87,12 +87,7 @@
describe 'kafka::broker::service' do
context 'service_install false' do
let :params do
{
config: {
'zookeeper.connect' => 'localhost:2181'
},
service_install: false
}
common_params.merge(service_install: false)
end
it { is_expected.not_to contain_file('kafka.service') }

Expand Down Expand Up @@ -134,4 +129,6 @@
end
end
end

it_validates_parameter 'mirror_url'
end
25 changes: 10 additions & 15 deletions spec/classes/consumer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'shared_examples_param_validation'

describe 'kafka::consumer', type: :class do
let :facts do
Expand All @@ -12,7 +13,7 @@
}
end

let :params do
let :common_params do
{
service_config: {
'topic' => 'demo',
Expand All @@ -21,6 +22,10 @@
}
end

let :params do
common_params
end

it { is_expected.to contain_class('kafka::consumer::install').that_comes_before('Class[kafka::consumer::service]') }
it { is_expected.to contain_class('kafka::consumer::service').that_comes_before('Class[kafka::consumer]') }
it { is_expected.to contain_class('kafka::consumer') }
Expand Down Expand Up @@ -77,31 +82,21 @@

context 'service_requires_zookeeper disabled' do
let :params do
{
service_requires_zookeeper: false,
service_config: {
'topic' => 'demo',
'zookeeper' => 'localhost:2181'
}
}
common_params.merge(service_requires_zookeeper: false)
end

it { should_not contain_file('kafka-consumer.service').with_content %r{^Requires=zookeeper.service$} }
end

context 'service_requires_zookeeper enabled' do
let :params do
{
service_requires_zookeeper: true,
service_config: {
'topic' => 'demo',
'zookeeper' => 'localhost:2181'
}
}
common_params.merge(service_requires_zookeeper: true)
end

it { should contain_file('kafka-consumer.service').with_content %r{^Requires=zookeeper.service$} }
end
end
end

it_validates_parameter 'mirror_url'
end
31 changes: 10 additions & 21 deletions spec/classes/mirror_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'shared_examples_param_validation'

describe 'kafka::mirror', type: :class do
let :facts do
Expand All @@ -12,7 +13,7 @@
}
end

let :params do
let :common_params do
{
consumer_config: {
'group.id' => 'kafka-mirror',
Expand All @@ -24,6 +25,10 @@
}
end

let :params do
common_params
end

it { is_expected.to contain_class('kafka::mirror::install').that_comes_before('Class[kafka::mirror::config]') }
it { is_expected.to contain_class('kafka::mirror::config').that_comes_before('Class[kafka::mirror::service]') }
it { is_expected.to contain_class('kafka::mirror::service').that_comes_before('Class[kafka::mirror]') }
Expand Down Expand Up @@ -93,37 +98,21 @@

context 'service_requires_zookeeper disabled' do
let :params do
{
service_requires_zookeeper: false,
consumer_config: {
'group.id' => 'kafka-mirror',
'zookeeper.connect' => 'localhost:2181'
},
producer_config: {
'bootstrap.servers' => 'localhost:9092'
}
}
common_params.merge(service_requires_zookeeper: false)
end

it { should_not contain_file('kafka-mirror.service').with_content %r{^Requires=zookeeper.service$} }
end

context 'service_requires_zookeeper enabled' do
let :params do
{
service_requires_zookeeper: true,
consumer_config: {
'group.id' => 'kafka-mirror',
'zookeeper.connect' => 'localhost:2181'
},
producer_config: {
'bootstrap.servers' => 'localhost:9092'
}
}
common_params.merge(service_requires_zookeeper: true)
end

it { should contain_file('kafka-mirror.service').with_content %r{^Requires=zookeeper.service$} }
end
end
end

it_validates_parameter 'mirror_url'
end
9 changes: 8 additions & 1 deletion spec/classes/producer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'shared_examples_param_validation'

describe 'kafka::producer', type: :class do
let :facts do
Expand All @@ -11,7 +12,7 @@
service_provider: 'upstart'
}
end
let :params do
let :common_params do
{
service_config: {
'broker-list' => 'localhost:9092',
Expand All @@ -21,6 +22,10 @@
}
end

let :params do
common_params
end

it { is_expected.to contain_class('kafka::producer::install').that_comes_before('Class[kafka::producer::config]') }
it { is_expected.to contain_class('kafka::producer::config').that_comes_before('Class[kafka::producer::service]') }
it { is_expected.to contain_class('kafka::producer::service').that_comes_before('Class[kafka::producer]') }
Expand Down Expand Up @@ -67,4 +72,6 @@
end
end
end

it_validates_parameter 'mirror_url'
end
67 changes: 67 additions & 0 deletions spec/shared_examples_param_validation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

RSpec.configure do |c|
c.alias_it_should_behave_like_to :it_validates_parameter, 'validates parameter:'
end

shared_examples 'mirror_url' do
domain_names = {
'foobar.com' => true,
'foo.bar.com' => true,
'999.bar.com' => true,
'foo-bar.com' => true,
'no-tld' => false,
'foo.longtld' => false
}

prefixes = {
'http://' => true,
'https://' => true,
'random://' => false
}

paths = {
'' => true,
'/' => true,
'/package' => true,
'/package/' => true,
'/another/package' => true,
'/yet/another/package/' => true
}

ports = {
'' => true,
':9' => false,
':10' => true,
':99999' => true,
':100000' => false
}

prefixes.each do |prefix, valid_prefix|
context "with prefix <#{prefix}>" do
domain_names.each do |domain_name, valid_domain|
context "with domain name <#{domain_name}>" do
paths.each do |path, valid_path|
context "with path <#{path}>" do
ports.each do |port, valid_port|
context "with port <#{port}>" do
mirror_url = "#{prefix}#{domain_name}#{port}#{path}"
context "URL => <#{mirror_url}>" do
let :params do
common_params.merge(mirror_url: mirror_url)
end

if valid_domain && valid_prefix && valid_path && valid_port
it { is_expected.to compile }
else
it { expect { is_expected.to compile }.to raise_error(%r{#{mirror_url} is not a valid url}) }
end
end
end
end
end
end
end
end
end
end
end