Skip to content

Commit

Permalink
Use reusable GitHub Actions for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nofaralfasi committed Feb 19, 2024
1 parent 2bebcce commit b2ef844
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 39 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI

on:
pull_request:
push:
branches:
- 'master'

concurrency:
group: ${{ github.ref_name }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
test:
name: Tests
uses: theforeman/actions/.github/workflows/test-gem.yml@v0
with:
command: bundle exec rake test

10 changes: 4 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ source "https://rubygems.org"
gemspec

gem 'gettext', '>= 3.1.3', '< 4.0.0'
if RUBY_VERSION < '2.1.0'
gem 'fast_gettext', '< 1.2.0'
end
gem 'rake', '~> 13.0'
gem 'hammer_cli_foreman', github: 'theforeman/hammer-cli-foreman', branch: 'master'

group :test do
gem 'rake', '>= 12.3.3'
gem 'thor'
gem 'minitest', '4.7.4'
gem 'minitest', '~> 5.18'
gem 'minitest-spec-context'
gem 'simplecov', '< 0.9.0' # 0.9.0 is not compatible with Ruby 1.8.x
gem 'simplecov'
gem 'mocha'
gem 'ci_reporter', '>= 1.6.3', "< 2.0.0", :require => false
end
Expand Down
5 changes: 3 additions & 2 deletions hammer_cli_foreman_discovery.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ DESC
s.extra_rdoc_files = Dir['LICENSE', 'README*']
s.require_paths = ["lib"]

s.add_dependency "hammer_cli_foreman", ">= 0.1.2"
s.add_development_dependency 'rake'
s.add_dependency 'hammer_cli_foreman', '~> 3.9'

s.required_ruby_version = '>= 2.7', '< 4'
end
24 changes: 12 additions & 12 deletions test/unit/discovery_rules_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@

include CommandTestHelper

context "ListCommand" do
describe "ListCommand" do
let(:cmd) { HammerCLIForemanDiscovery::DiscoveryRule::ListCommand.new("", ctx) }

before :each do
DiscoveryResourceMock.discovery_rules_index
end

context "parameters" do
describe "parameters" do
it_should_accept "no arguments"
it_should_accept_search_params
end

context "output" do
describe "output" do
let(:expected_record_count) { cmd.resource.call(:index).length }
it_should_print_n_records
it_should_print_columns ["ID", "Name", "Priority", "Search", "Host Group", "Hosts Limit", "Enabled"]
end
end

context "InfoCommand" do
describe "InfoCommand" do

let(:cmd) { HammerCLIForemanDiscovery::DiscoveryRule::InfoCommand.new("", ctx) }

before :each do
cmd.stubs(:get_parameters).returns([])
end

context "parameters" do
describe "parameters" do
it_should_accept "id", ["--id=1"]
it_should_accept "name", ["--name=rule"]
end

context "output" do
describe "output" do
with_params ["--id=1"] do
it_should_print_n_records 1
it_should_print_columns ["ID", "Name", "Priority", "Search", "Host Group", "Hosts Limit", "Enabled", "Hostname template", "Hosts", "Locations", "Organizations"]
Expand All @@ -50,22 +50,22 @@

end

context "DeleteCommand" do
describe "DeleteCommand" do

let(:cmd) { HammerCLIForemanDiscovery::DiscoveryRule::DeleteCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "name", ["--name=rule"]
it_should_accept "id", ["--id=1"]
end

end

context "CreateCommand" do
describe "CreateCommand" do

let(:cmd) { HammerCLIForemanDiscovery::DiscoveryRule::CreateCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "name, priority, search, hostgroup, hostgroup-id, hosts-limit, locations, organizations and enabled",
["--name=rule", "--priority=1", "--search='cpu_count > 1'",
"--hostgroup='test'", "--hostgroup-id=1", "--hosts-limit=1",
Expand All @@ -84,11 +84,11 @@
end
end

context "UpdateCommand" do
describe "UpdateCommand" do

let(:cmd) { HammerCLIForemanDiscovery::DiscoveryRule::UpdateCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "id, name, priority, search, hostgroup, hostgroup-id, hosts-limit and enabled",
["--id=1", "--name=rule", "--priority=1", "--search=cpu_count > 1", "--hostgroup='test'", "--hostgroup-id=1", "--hosts-limit=1", "--enabled=true"]
it_should_accept "name", ["--name=rule", "--new-name=rule2"]
Expand Down
38 changes: 19 additions & 19 deletions test/unit/discovery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@

include CommandTestHelper

context "ListCommand" do
describe "ListCommand" do
let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::ListCommand.new("", ctx) }

before :each do
DiscoveryResourceMock.discovered_hosts_index
end

context "parameters" do
describe "parameters" do
it_should_accept "no arguments"
it_should_accept_search_params
end

context "output" do
describe "output" do
let(:expected_record_count) { cmd.resource.call(:index).length }
it_should_print_n_records
it_should_print_columns ["ID", "Name", "MAC", "Last report", "Subnet", "CPUs", "Memory", "Disk count", "Disks size"]
end
end

context "InfoCommand" do
describe "InfoCommand" do

let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::InfoCommand.new("", ctx) }

before :each do
cmd.stubs(:get_parameters).returns([])
end

context "parameters" do
describe "parameters" do
it_should_accept "id", ["--id=1"]
it_should_accept "name", ["--name=host"]
end

context "output" do
describe "output" do
with_params ["--id=1"] do
it_should_print_n_records 1
it_should_print_columns ["ID", "Name", "MAC", "Last report", "Subnet", "CPUs", "Memory", "Disk count", "Disks size", "Organization", "Location"]
Expand All @@ -51,21 +51,21 @@

end

context "DeleteCommand" do
describe "DeleteCommand" do

let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::DeleteCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "name", ["--name=host"]
it_should_accept "id", ["--id=1"]
end

end

context "ProvisionCommand" do
describe "ProvisionCommand" do
let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::ProvisionCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "name, architecture_id, domain_id, operatingsystem_id and more",
["--name=host", "--architecture-id=1", "--domain-id=1", "--operatingsystem-id=1",
"--ip=1.2.3.4", "--mac=11:22:33:44:55:66", "--medium-id=1", "--partition-table-id=1", "--subnet-id=1",
Expand All @@ -84,48 +84,48 @@
end
end

context "AutoProvisionCommand" do
describe "AutoProvisionCommand" do

let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::AutoProvisionCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "name", ["--name=host"]
it_should_accept "id", ["--id=1"]
end

end

context "RebootCommand" do
describe "RebootCommand" do
let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::RebootCommand.new("", ctx) }
context "parameters" do
describe "parameters" do
it_should_accept "name", ["--name=host"]
it_should_accept "id", ["--id=1"]
end
end

context "RefreshFactsCommand" do
describe "RefreshFactsCommand" do
let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::RefreshFactsCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "name", ["--name=host"]
it_should_accept "id", ["--id=1"]
end
end

context "FactsCommand" do
describe "FactsCommand" do

let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::FactsCommand.new("", ctx) }

before(:each) do
DiscoveryResourceMock.facts_index
end

context "parameters" do
describe "parameters" do
it_should_accept "name", ["--name=mac52540068f9d6"]
it_should_accept "id", ["--id=1"]
end

context "output" do
describe "output" do
with_params ["--name=mac52540068f9d6"] do
it_should_print_column "Fact"
it_should_print_column "Value"
Expand Down

0 comments on commit b2ef844

Please sign in to comment.