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

Add unit test to validate library assumptions #49

Merged
merged 2 commits into from
Aug 13, 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
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
---
AllCops:
Exclude:
- Gemfile
- Rakefile
- 'vendor/**/*'
Metrics/LineLength:
Max: 160
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ group :development do
gem 'rake', '< 11'
gem 'foodcritic', '~> 4.0'
gem 'cookstyle'
gem 'rspec'
end

group :appveyor do
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ DEPENDENCIES
github_changelog_generator
kitchen-localhost
rake (< 11)
rspec
stove

BUNDLED WITH
Expand Down
14 changes: 12 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require 'stove/rake_task'
require 'cookstyle'
require 'rubocop/rake_task'
require 'foodcritic'
require 'rspec/core/rake_task'

# Publish This cookbook
Stove::RakeTask.new
Expand All @@ -24,11 +25,20 @@ namespace :style do
end
end

# Style tests. Rubocop and Foodcritic
namespace :test do
desc 'Run rspec'
RSpec::Core::RakeTask.new(:unit)
end

desc 'Run all style checks'
task style: ['style:chef', 'style:ruby']

desc 'Run all test'
task test: ['test:unit']

desc 'Run all tests on Travis'
task travis: ['style']
task travis: ['style', 'test']

# Default
task default: ['style']
task default: :travis
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$LOAD_PATH.unshift File.dirname('./libraries')
19 changes: 19 additions & 0 deletions spec/unit/lib_shared_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'spec_helper'
require 'libraries/shared'

describe 'OctopusDeploy::Shared' do
let(:shared) { Class.new { include OctopusDeploy::Shared }.new }

describe 'powershell_boolean' do
it 'should return uppercased bools' do
expect(shared.powershell_boolean(true)).to eq 'True'
expect(shared.powershell_boolean(false)).to eq 'False'
end
end

describe 'catch_powershell_error' do
it 'should return a error statement with the specified error text' do
expect(shared.catch_powershell_error('HELLO_WORLD')).to match(/throw "ERROR: .* HELLO_WORLD.*/)
end
end
end
48 changes: 48 additions & 0 deletions spec/unit/lib_tentacle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'spec_helper'
require 'libraries/tentacle'

describe 'OctopusDeploy::Tentacle' do
let(:tentacle) { Class.new { include OctopusDeploy::Tentacle }.new }

describe 'display_name' do
it 'should return the correct display name' do
expect(tentacle.display_name).to eq 'Octopus Deploy Tentacle'
end
end

describe 'service_name' do
it 'should return the correct service name for the default instance name' do
expect(tentacle.service_name('Tentacle')).to eq 'OctopusDeploy Tentacle'
end

it 'should return the correct service name for non a default instance name' do
expect(tentacle.service_name('Instance')).to eq 'OctopusDeploy Tentacle: Instance'
end
end

describe 'tentacle_install_location' do
it 'should exist' do
expect(tentacle).to respond_to :tentacle_install_location
end
end

describe 'installer_url' do
it 'should exist' do
expect(tentacle).to respond_to :installer_url
end
end

describe 'resolve_port' do
it 'should return the port that is specified' do
expect(tentacle.resolve_port(true, 100)).to eq 100
end

it 'should return the 10943 for a polling tentacle with no port' do
expect(tentacle.resolve_port(true, nil)).to eq 10_943
end

it 'should return the 10933 for a listening tentacle with no port' do
expect(tentacle.resolve_port(false, nil)).to eq 10_933
end
end
end