Skip to content

Commit

Permalink
Add package version to user agent
Browse files Browse the repository at this point in the history
To enhance the 'User-Agent' used in the request headers, this commit
adds the module constant `RMT::Version`, which must always match the
package version specified in 'package/yast2-rmt.spec'.

Additionally, a unit test was created to ensure the versions always
match each other; if there is a version bump in packge spec file, the
RSpec tests will break if 'src/lib/rmt.rb' is not updated accordingly.
  • Loading branch information
lcaparroz committed Feb 14, 2024
1 parent 04dd0fb commit 8c5cfa7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions spec/rmt_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'rmt'

describe RMT do
describe '.VERSION' do
subject(:version) { RMT::VERSION }

let(:package_version) do
filename = './package/yast2-rmt.spec'
version = nil

File.foreach(filename) do |line|
line.match(/^Version:\s+(?<version>(\d+\.?){3})$/) do |match|
version ||= match.named_captures['version']
end
end

raise "'#{filename}' does not include any line matching the expected package version format." if version.nil?

version
end

it 'returns the same version as specified in the package spec file' do
expect(version).to eq package_version
end
end
end
3 changes: 3 additions & 0 deletions src/lib/rmt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module RMT
VERSION = '1.3.5'.freeze
end
3 changes: 2 additions & 1 deletion src/lib/rmt/wizard_scc_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

require 'uri'
require 'net/http'
require 'rmt'
require 'rmt/utils'
require 'ui/event_dispatcher'

Expand All @@ -26,7 +27,7 @@ module RMT; end
class RMT::WizardSCCPage < Yast::Client
include ::UI::EventDispatcher

YAST_RMT_USER_AGENT = 'yast2-rmt'.freeze
YAST_RMT_USER_AGENT = "yast2-rmt/#{RMT::VERSION}".freeze

def initialize(config)
textdomain 'rmt'
Expand Down

0 comments on commit 8c5cfa7

Please sign in to comment.