Skip to content

Commit b9c3339

Browse files
committed
test: Add integration testing
1 parent d3e678b commit b9c3339

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

Rakefile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,24 @@ RuboCop::RakeTask.new do |task|
99
end
1010
RSpec::Core::RakeTask.new(:spec)
1111

12-
task default: %i[rubocop spec]
12+
task default: %i[rubocop spec integration]
13+
14+
desc 'Build the ONA development container with podman'
15+
task :build_onadev_container do
16+
unless system('podman image exists localhost/ona-dev:latest')
17+
`podman login docker.io`
18+
`git clone https://github.com/opennetadmin/ona onadev`
19+
`podman build --build-arg UBUNTU_VERSION=24.04 -t ona-dev:latest onadev`
20+
`rm -rf onadev`
21+
end
22+
end
23+
24+
desc 'Publish ONA development container to ghcr.io'
25+
task publish_onadev_container_to_ghcr: :build_onadev_container do
26+
`podman login ghcr.io`
27+
`podman image push localhost/ona-dev:latest docker://ghcr.io/gsi-hpc/ona-dev:latest`
28+
end
29+
30+
RSpec::Core::RakeTask.new(:integration) do |task|
31+
task.pattern = 'integration/**{,/*/**}/*_spec.rb'
32+
end

integration/ona_spec.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# frozen_string_literal: true
2+
3+
require 'ona'
4+
require 'net/http'
5+
6+
# Generate new port number each time asked
7+
class PortManager
8+
@next_port = 11_080
9+
10+
def self.next_port
11+
port = @next_port
12+
@next_port += 1
13+
port
14+
end
15+
end
16+
17+
def with_retries(max_retries = 30)
18+
(1..max_retries).each do
19+
begin
20+
yield
21+
return
22+
rescue StandardError
23+
# do nothing
24+
end
25+
sleep(0.2)
26+
end
27+
raise "max retries #{max_retries} reached, aborting"
28+
end
29+
30+
def ephemeral_onadev_container
31+
host = 'localhost'
32+
port = PortManager.next_port
33+
container_prefix = 'onadev_'
34+
dcm_path = '/ona/dcm.php'
35+
@dcm_endpoint = "http://#{host}:#{port}#{dcm_path}"
36+
name = "#{container_prefix}#{port}"
37+
38+
# define and start ephemeral (--rm) container
39+
`podman container create -p #{port}:80 --name #{name} --rm docker://ghcr.io/gsi-hpc/ona-dev:latest`
40+
`podman container start #{name}`
41+
42+
# wait for webserver
43+
with_retries do
44+
res = Net::HTTP.start(host, port).get(dcm_path)
45+
raise unless res.is_a?(Net::HTTPSuccess)
46+
end
47+
48+
yield
49+
ensure
50+
`podman container kill #{name}`
51+
end
52+
53+
describe ONA do
54+
subject(:ona) { described_class.new(@dcm_endpoint, 'admin', 'admin') } # rubocop:disable RSpec/InstanceVariable
55+
56+
around { |ex| ephemeral_onadev_container(&ex) }
57+
58+
describe 'get_module_list' do
59+
subject(:result) { ona.query('get_module_list', { type: 'array' }) }
60+
61+
it 'returns the module list' do
62+
expect(result).to be_an_instance_of(Hash).and \
63+
include('domain_display')
64+
end
65+
end
66+
67+
describe 'domain_display' do
68+
subject(:result) { ona.query('domain_display', { domain: 'example.com' }) }
69+
70+
it { is_expected.to include('fqdn' => 'example.com') }
71+
end
72+
end

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@
2929
# inherited by the metadata hash of host groups and examples, rather than
3030
# triggering implicit auto-inclusion in groups with matching metadata.
3131
config.shared_context_metadata_behavior = :apply_to_host_groups
32+
33+
config.formatter = :documentation
3234
end

0 commit comments

Comments
 (0)