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 Oct 26, 2023
1 parent c16c6ab commit 24f5ffb
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
56 changes: 56 additions & 0 deletions testsuite/features/reposync/srv_sync_repo_sync.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) 2023 SUSE LLC
# Licensed under the terms of the MIT license.

@susemanager
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

@susemanager
Scenario: Run synchronization with default strict mode
Given I am authorized for the "Admin" section
And I prepare a channel clone for strict mode testing
And I am on the Channels page
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

And I follow "Repositories" in the content area
And I follow "Create Repository"
And I enter "TestRepo_Default" as "Repository Label"
And I enter "http://localhost/pub/TestRepoRpmUpdates/" as "Repository URL"
And I follow "Create Repository"
Then I should see a "Repository created successfully" text

And I follow "Create Repository"
And I enter "TestRepo_Modified" as "Repository Label"
And I enter "http://localhost/pub/TestRepoRpmUpdates_STRICT_TEST/" as "Repository URL"
And I uncheck "Has Signed Metadata"
And I follow "Create Repository"
Then I should see a "Repository created successfully" text

And I check "TestRepo_Default"
And I follow "Save Repositories"
And I follow "Sync"
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 "TestRepo_Default"
And I check "TestRepo_Modified"
And I follow "Save Repositories"
And I follow "Sync"
And I check "Do not use strict mode"
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 am logged into the API
Then The amount of packages in channel "Test-Strict-Channel" should be the same as before

And I uncheck "Do not use strict mode"
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 fewer than before
49 changes: 49 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,55 @@
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
api_url = "https://localhost/rhn/manager/api/auth/login"
response = RestClient.post(api_url, { login: "admin", password: "admin" }.to_json, { content_type: :json })
raise "Failed to login to the API" unless response.code == 200

$api_token = response.cookies["pxt-session-cookie"]
end

$previous_packages_count = nil

When(/^i check the amount of packages in channel "([^"]*)"$/) do |channel_label|
api_url = "https://localhost/rhn/manager/api/listAllChannels"
response = RestClient.get(api_url, { content_type: :json, cookie: "pxt-session-cookie=#{$api_token}" })
channels = JSON.parse(response.body)["result"]
channel = channels.find { |c| c["label"] == channel_label }
raise "Channel not found" unless channel
$previous_packages_count = channel["packages"]
end

Then(/^The amount of packages in channel "([^"]*)" should be the same as before$/) do |channel_label|
api_url = "https://localhost/rhn/manager/api/listAllChannels"
response = RestClient.get(api_url, { content_type: :json, cookie: "pxt-session-cookie=#{$api_token}" })
channels = JSON.parse(response.body)["result"]
channel = channels.find { |c| c["label"] == channel_label }
raise "Channel not found" unless channel
raise "Package counts do not match" unless $previous_packages_count == channel["packages"]
end

Then(/^The amount of packages in channel "([^"]*)" should be fewer than before$/) do |channel_label|
api_url = "https://localhost/rhn/manager/api/listAllChannels"
response = RestClient.get(api_url, { content_type: :json, cookie: "pxt-session-cookie=#{$api_token}" })
channels = JSON.parse(response.body)["result"]
channel = channels.find { |c| c["label"] == channel_label }
raise "Channel not found" unless channel
raise "Package count is not fewer than before" unless channel["packages"] < $previous_packages_count
end

When(/^I delete these channels with spacewalk-remove-channel:$/) do |table|
channels_cmd = 'spacewalk-remove-channel '
Expand Down

0 comments on commit 24f5ffb

Please sign in to comment.