From 5f6a2fcbcffe178dabccb7c7fc5937dab9f62814 Mon Sep 17 00:00:00 2001 From: Paolo Invernizzi Date: Mon, 30 Sep 2024 14:02:54 +0200 Subject: [PATCH] QE: Add tests for channels.appstreams API namespace (#9204) * QE: Add API support for channels.appstreams namespace * QE: add test scenarios for channel.appstreams API namespace * Rubocop fixes * fix method call --- .../secondary/srv_channel_api.feature | 15 ++++++- .../features/step_definitions/api_common.rb | 29 ++++++++++++++ .../features/support/namespaces/channel.rb | 39 ++++++++++++++++++- 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/testsuite/features/secondary/srv_channel_api.feature b/testsuite/features/secondary/srv_channel_api.feature index ea381b0c2706..f9bb77d68780 100644 --- a/testsuite/features/secondary/srv_channel_api.feature +++ b/testsuite/features/secondary/srv_channel_api.feature @@ -1,4 +1,4 @@ -# Copyright (c) 2015-2022 SUSE LLC +# Copyright (c) 2015-2024 SUSE LLC # Licensed under the terms of the MIT license. @scope_api @@ -37,3 +37,16 @@ Feature: API "channel" namespace and sub-namespaces Scenario: Check last synchronization of a synced channel Then channel "fake-child-channel-i586" should have attribute "yumrepo_last_sync" that is a date + + @rhlike_minion + Scenario: Verify if a channel is modular via the API + When I verify channel "fake-base-channel-appstream" is modular via the API + And I verify channel "fake-rpm-suse-channel" is not modular via the API + + @rhlike_minion + Scenario: List modular channels via the API + When channel "Fake-Base-Channel-AppStream" is present in the modular channels listed via the API + + @rhlike_minion + Scenario: List available module streams for a given channel via the API + When "scorpio" module streams "2.0, 2.1" are available for channel "fake-base-channel-appstream" via the API diff --git a/testsuite/features/step_definitions/api_common.rb b/testsuite/features/step_definitions/api_common.rb index 9de6387a5fad..0eb73b62575c 100644 --- a/testsuite/features/step_definitions/api_common.rb +++ b/testsuite/features/step_definitions/api_common.rb @@ -631,3 +631,32 @@ When(/^I delete profile and distribution using the API for "([^"]*)" kickstart tree$/) do |distro_name| $api_test.kickstart.tree.delete_tree_and_profiles(distro_name) end + +When(/I verify channel "([^"]*)" is( not)? modular via the API/) do |channel_label, not_modular| + is_modular = $api_test.channel.appstreams.modular?(channel_label) + expected = not_modular.nil? + + raise ScriptError "channel '#{channel_label}' is modular? Expected: #{expected} - got: #{is_modular}" unless is_modular == expected +end + +When(/channel "([^"]*)" is( not)? present in the modular channels listed via the API/) do |channel, not_present| + modular_channels = $api_test.channel.appstreams.list_modular_channels + is_present = modular_channels.include?(channel) + expected = not_present.nil? + + raise ScriptError "Expected #{modular_channels} to include '#{channel}'? #{expected} - got: #{is_present}" unless is_present == expected +end + +When(/"([^"]*)" module streams "([^"]*)" are available for channel "([^"]*)" via the API/) do |module_name, streams, channel_label| + expected_streams = streams.split(',').map(&:strip) + available_streams = $api_test.channel.appstreams.list_module_streams(channel_label) + + expected_streams.each do |expected_stream| + found = + available_streams.any? do |stream| + stream['module'] == module_name && stream['stream'] == expected_stream + end + + raise ScriptError, "Stream '#{expected_stream}' for module '#{module_name}' not found in the available streams for channel '#{channel_label}'" unless found + end +end diff --git a/testsuite/features/support/namespaces/channel.rb b/testsuite/features/support/namespaces/channel.rb index 394db1899624..8b79cb75249e 100644 --- a/testsuite/features/support/namespaces/channel.rb +++ b/testsuite/features/support/namespaces/channel.rb @@ -9,9 +9,10 @@ class NamespaceChannel def initialize(api_test) @test = api_test @software = NamespaceChannelSoftware.new(api_test) + @appstreams = NamespaceChannelAppstreams.new(api_test) end - attr_reader :software + attr_reader :software, :appstreams # It returns the number of software channels in the system. # @@ -164,3 +165,39 @@ def list_system_channels(system_id) channels.map { |channel| channel['name'] } end end + +# channel.appstreams namespace +class NamespaceChannelAppstreams + # Initializes a new instance of the NamespaceChannelAppstreams class. + # + # @param api_test [Object] The test object that is passed to the initialize method. + def initialize(api_test) + @test = api_test + end + + # Check if channel is modular. + # + # @param label [String] The label of the channel. + # + # @return [Boolean] Returns true if the channel is modular, false otherwise + def modular?(label) + @test.call('channel.appstreams.isModular', sessionKey: @test.token, channelLabel: label) + end + + # List modular channels in users organization. + # + # @return [Array] An array of modular channel names. + def list_modular_channels + channels = @test.call('channel.appstreams.listModular', sessionKey: @test.token) + channels.map { |channel| channel['name'] } + end + + # List available module streams for a given channel. + # + # @param label [String] The label of the channel. + # + # @return [Array] An array of objects representing each stream details + def list_module_streams(label) + @test.call('channel.appstreams.listModuleStreams', sessionKey: @test.token, channelLabel: label) + end +end