Skip to content

Commit

Permalink
Add cucumber test for strict mode functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
r-richardson committed Dec 14, 2023
1 parent eb4ec9c commit 572469d
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
55 changes: 55 additions & 0 deletions testsuite/features/reposync/srv_sync_repo_sync.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2023 SUSE LLC
# Licensed under the terms of the MIT license.

Feature: Strict Mode for Channel Synchronization
In order to control strict mode synchronization
As an admin user
I want to be able to toggle strict mode synchronization via the UI and command line

Scenario: Create Test-strict-channel
Given I am authorized for the "Admin" section
And I prepare a channel clone for strict mode testing
And I follow the left menu "Software > Manage > Channels"
And I follow "Create Channel"
And I enter "Test-Strict-Channel" as "Channel Name"
And I enter "test-strict-channel" as "Channel Label"
And I enter "Test-Strict-Channel for testing" as "Channel Summary"
And I click on "Create Channel"
Then I should see a "Channel Test-Strict-Channel created." text

Scenario: Prepare repos for strict test
Given I am authorized for the "Admin" section
And I follow the left menu "Software > Manage > Repositories"
And I follow "Create Repository"
And I enter "fake-rpm-repo-modified" as "label"
And I enter "http://localhost/pub/TestRepoRpmUpdates_STRICT_TEST/" as "url"
And I uncheck "metadataSigned"
And I click on "Create Repository"
Then I should see a "Repository created successfully" text

@rrichardson-test
Scenario: Testing strict mode
Given I am authorized for the "Admin" section
And I follow the left menu "Software > Manage > Channels"
And I follow "Test-Strict-Channel"
And I follow "Repositories" in the "content area"
And I check "fake-rpm-repo" in the list
And I click on "Save Repositories"
And I follow "Sync" in the "content area"
And I click on "Sync Now"
And I wait at most 60 seconds until I do not see "Repository sync is running." text, refreshing the page
And I check the amount of packages in channel "test-strict-channel"
And I follow "Add / Remove"
And I uncheck "fake-rpm-repo" in the list
And I check "fake-rpm-repo-modified" in the list
And I click on "Save Repositories"
And I follow "Sync" in the "content area"
And I check "no-strict"
And I click on "Sync Now"
And I wait at most 60 seconds until I do not see "Repository sync is running." text, refreshing the page
Then The amount of packages in channel "Test-Strict-Channel" should be the same as before

And I uncheck "no-strict"
And I click on "Sync Now"
And I wait at most 60 seconds until I do not see "Repository sync is running." text, refreshing the page
Then The amount of packages in channel "Test-Strict-Channel" should be fewer than before
43 changes: 43 additions & 0 deletions testsuite/features/step_definitions/command_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,49 @@
end

# Channels
When(/^I prepare a channel clone for strict mode testing$/) do
get_target('server').run('cp -r /srv/www/htdocs/pub/TestRepoRpmUpdates /srv/www/htdocs/pub/TestRepoRpmUpdates_STRICT_TEST')
get_target('server').run('rm -rf /srv/www/htdocs/pub/TestRepoRpmUpdates_STRICT_TEST/repodata')
%w[i586 src x86_64].each do |folder|
get_target('server').run("rm -f /srv/www/htdocs/pub/TestRepoRpmUpdates_STRICT_TEST/#{folder}/rute-dummy-2.0-1.2.*.rpm")
end
get_target('server').run('createrepo_c /srv/www/htdocs/pub/TestRepoRpmUpdates_STRICT_TEST')
get_target('server').run('gzip -dc /srv/www/htdocs/pub/TestRepoRpmUpdates/repodata/*-updateinfo.xml.gz > /tmp/updateinfo.xml')
get_target('server').run('modifyrepo_c --verbose --mdtype updateinfo /tmp/updateinfo.xml /srv/www/htdocs/pub/TestRepoRpmUpdates_STRICT_TEST/repodata')
end

Given(/^I am logged into the API$/) do
server_node = get_target('server')
api_url = "https://#{server_node.public_ip}/rhn/manager/api/auth/login"
response = get_target('server').run("curl -H 'Content-Type: application/json' -d '{'login': 'admin', 'password': 'admin'}' -i #{api_url}")
raise 'Failed to login to the API' unless response.code == 200
end

$package_amount = nil

When(/^I check the amount of packages in channel "([^"]*)"$/) do |channel_label|
channels = $api_test.channel.list_all_channels
if channels.key?(channel_label)
package_amount = channels[channel_label]['packages']
puts "Package amount for 'test-strict': #{package_amount}"
else
puts "#{channel_label} channel not found."
end
end

Then(/^The amount of packages in channel "([^"]*)" should be the same as before$/) do |channel_label|
channels = $api_test.channel.list_all_channels
if channels.key?(channel_label) && ($package_amount != channels[channel_label]['packages'])
raise 'Package counts do not match'
end
end

Then(/^The amount of packages in channel "([^"]*)" should be fewer than before$/) do |channel_label|
channels = $api_test.channel.list_all_channels
if channels.key?(channel_label) && channels[channel_label]['packages'] >= $package_amount
raise 'Package count is not fewer than before'
end
end

When(/^I delete these channels with spacewalk-remove-channel:$/) do |table|
channels_cmd = 'spacewalk-remove-channel '
Expand Down
8 changes: 8 additions & 0 deletions testsuite/features/step_definitions/navigation_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,14 @@
row.set(true)
end

When(/^I uncheck "([^"]*)" in the list$/) do |text|
top_level_xpath_query = "//div[@class=\"table-responsive\"]/table/tbody/tr[.//td[contains(.,'#{text}')]]//input[@type='checkbox']"
row = find(:xpath, top_level_xpath_query, match: :first)
raise "xpath: #{top_level_xpath_query} not found" if row.nil?

row.set(false)
end

#
# Test if an option is selected
#
Expand Down
20 changes: 20 additions & 0 deletions testsuite/features/support/namespaces/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ def verify_channel(label)
.include?(label)
end

def list_all_channels
channels = @test.call('channel.listAllChannels', sessionKey: @test.token)

mapped_channels =
channels.map do |channel|
[
channel['label'],
{
'id' => channel['id'],
'name' => channel['name'],
'provider_name' => channel['provider_name'],
'packages' => channel['packages'],
'systems' => channel['systems'],
'arch_name' => channel['arch_name']
}
]
end
mapped_channels.to_h
end

def list_software_channels
channels = @test.call('channel.listSoftwareChannels', sessionKey: @test.token)
channels.map { |channel| channel['label'] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- features/reposync/srv_create_fake_repositories.feature
- features/reposync/srv_sync_fake_channels.feature
- features/reposync/srv_create_activationkey.feature
- features/reposync/srv_sync_repo_sync.feature
- features/core/srv_osimage.feature
- features/core/srv_docker.feature
## Container features END ###

0 comments on commit 572469d

Please sign in to comment.