From 2ce4c27a7b479cb464a1339b659aea6e6dc38a17 Mon Sep 17 00:00:00 2001 From: r-richardson Date: Thu, 26 Oct 2023 16:45:42 +0200 Subject: [PATCH] Add cucumber test for strict mode functionality --- .../reposync/srv_sync_repo_sync.feature | 55 +++++++++++++++++++ .../step_definitions/command_steps.rb | 46 ++++++++++++++++ .../step_definitions/navigation_steps.rb | 8 +++ .../features/support/namespaces/channel.rb | 18 ++++++ 4 files changed, 127 insertions(+) create mode 100644 testsuite/features/reposync/srv_sync_repo_sync.feature diff --git a/testsuite/features/reposync/srv_sync_repo_sync.feature b/testsuite/features/reposync/srv_sync_repo_sync.feature new file mode 100644 index 000000000000..3edae5612be9 --- /dev/null +++ b/testsuite/features/reposync/srv_sync_repo_sync.feature @@ -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 diff --git a/testsuite/features/step_definitions/command_steps.rb b/testsuite/features/step_definitions/command_steps.rb index e48240def98b..af4c34627583 100644 --- a/testsuite/features/step_definitions/command_steps.rb +++ b/testsuite/features/step_definitions/command_steps.rb @@ -117,6 +117,52 @@ 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 + +$api_token = nil # TODO: Move elsewhere ? + +Given(/^I am logged into the API$/) do # TODO: Move elsewhere ? + 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 + $api_token = response.cookies["pxt-session-cookie"] +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) + raise "Package counts do not match" unless $package_amount == channels[channel_label]["packages"] + 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) + raise "Package count is not fewer than before" unless channels[channel_label]["packages"] < $package_amount + end +end When(/^I delete these channels with spacewalk-remove-channel:$/) do |table| channels_cmd = 'spacewalk-remove-channel ' diff --git a/testsuite/features/step_definitions/navigation_steps.rb b/testsuite/features/step_definitions/navigation_steps.rb index 504575bff9e8..687b22ef319a 100644 --- a/testsuite/features/step_definitions/navigation_steps.rb +++ b/testsuite/features/step_definitions/navigation_steps.rb @@ -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 # diff --git a/testsuite/features/support/namespaces/channel.rb b/testsuite/features/support/namespaces/channel.rb index 47ce0cc589d9..80cdbcd84597 100644 --- a/testsuite/features/support/namespaces/channel.rb +++ b/testsuite/features/support/namespaces/channel.rb @@ -33,6 +33,24 @@ def verify_channel(label) .include?(label) end + def list_all_channels + channels = @test.call('channel.listAllChannels', sessionKey: @test.token) + + 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.to_h + end + def list_software_channels channels = @test.call('channel.listSoftwareChannels', sessionKey: @test.token) channels.map { |channel| channel['label'] }