From 4d5e03b81bb45583756f244e0013bd9ff1abfbcf Mon Sep 17 00:00:00 2001 From: Preetham Kamidi Date: Thu, 17 Jul 2025 11:31:50 +0000 Subject: [PATCH] Add: Support for Faraday 2.x Signed-off-by: Preetham Kamidi Update: Version Signed-off-by: Preetham Kamidi Fix: Header pattern Signed-off-by: Preetham Kamidi Fix: Smoke tests Signed-off-by: Preetham Kamidi Fix: Unit tests Signed-off-by: Preetham Kamidi Fix: Switch to safe_load Signed-off-by: Preetham Kamidi Update: Switch to CodeQL v3 Signed-off-by: Preetham Kamidi --- .github/workflows/main.yml | 24 +++--- lib/sgtn-client/loader/server.rb | 8 +- lib/sgtn-client/loader/source.rb | 4 +- lib/sgtn-client/sgtn-client.rb | 4 +- lib/version.rb | 4 +- singleton-client.gemspec | 5 +- spec/loader/mix_spec.rb | 122 +++++++++++++++---------------- spec/support/helpers.rb | 10 +-- spec/support/sample_data.rb | 5 +- 9 files changed, 95 insertions(+), 91 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a9b25270b..b5b7e2c40 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,7 +53,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.0.0 + ruby-version: 3.3 - name: Install dependencies run: bundle install - name: Unit test @@ -80,17 +80,17 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.0.0 + ruby-version: 3.3 - name: Install dependencies run: bundle install - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v3 with: languages: ruby - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v3 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v3 codacy-analysis-cli: name: Codacy Analysis CLI @@ -125,25 +125,25 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.0.0 + ruby-version: 3.3 - name: Install dependencies run: bundle install - - name: Set up JDK 8 + - name: Set up JDK 17 uses: actions/setup-java@v2 with: - distribution: 'adopt' - java-version: '8' + distribution: 'temurin' + java-version: '17' - name: Smoke Test run: | export PATH=${PATH/:\/usr\/local\/lib\/jvm\/openjdk11\/bin:/:} sudo apt-get update - sudo apt-get install -y openjdk-8-jdk - export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64" + sudo apt-get install -y openjdk-17-jdk + export JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64" git clone --branch=master https://github.com/vmware/singleton.git server git clone --branch=devops https://github.com/vmware/singleton.git devops cd $GITHUB_WORKSPACE/server/g11n-ws && ./gradlew build -x test cp $GITHUB_WORKSPACE/devops/deploy/i18n-service/Dockerfile $GITHUB_WORKSPACE/server/publish/ - cd $GITHUB_WORKSPACE/server/publish && mv singleton-[0~9]*.jar i18n-service.jar + cd $GITHUB_WORKSPACE/server/publish && mv singleton-0.1.0.jar i18n-service.jar docker build -t singleton . docker run -d -p 8090:8090 -p 8091:8091 --name singleton singleton docker ps diff --git a/lib/sgtn-client/loader/server.rb b/lib/sgtn-client/loader/server.rb index 04ab78a1f..e15731655 100644 --- a/lib/sgtn-client/loader/server.rb +++ b/lib/sgtn-client/loader/server.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -# Copyright 2022 VMware, Inc. +# Copyright 2025 VMware, Inc. # SPDX-License-Identifier: EPL-2.0 require 'faraday' -require 'faraday_middleware' +require 'faraday/gzip' require 'set' module SgtnClient @@ -26,10 +26,10 @@ def initialize(config) @components_url = "#{product_root}/componentlist" @conn = Faraday.new(config.vip_server, request: REQUEST_ARGUMENTS) do |f| - f.response :json # decode response bodies as JSON + f.response :json f.response :raise_error f.response :logger, config.logger, { log_level: :debug, headers: false, bodies: true } - f.use :gzip + f.request :gzip end end diff --git a/lib/sgtn-client/loader/source.rb b/lib/sgtn-client/loader/source.rb index 127d6b4e8..b6ef8fd32 100644 --- a/lib/sgtn-client/loader/source.rb +++ b/lib/sgtn-client/loader/source.rb @@ -1,4 +1,4 @@ -# Copyright 2022-2023 VMware, Inc. +# Copyright 2025 VMware, Inc. # SPDX-License-Identifier: EPL-2.0 require 'pathname' @@ -20,7 +20,7 @@ def load_bundle(component, locale = nil) total_messages = {} Pathname.glob(@source_bundle_path + component + '**/*.{yml, yaml}') do |f| - bundle = YAML.load(File.read(f)) + bundle = YAML.safe_load(File.read(f), aliases: true) messages = bundle&.first&.last # TODO: Warn about inconsistent source locale if messages.is_a?(Hash) total_messages.merge!(messages) diff --git a/lib/sgtn-client/sgtn-client.rb b/lib/sgtn-client/sgtn-client.rb index 5e696d152..a737c7979 100644 --- a/lib/sgtn-client/sgtn-client.rb +++ b/lib/sgtn-client/sgtn-client.rb @@ -1,4 +1,4 @@ -# Copyright 2022 VMware, Inc. +# Copyright 2025 VMware, Inc. # SPDX-License-Identifier: EPL-2.0 require 'forwardable' @@ -30,7 +30,7 @@ class << self def_delegators :config, :logger, :logger= def load(config_file, env, log_file = nil) - configurations = YAML.load(File.read(config_file)) + configurations = YAML.safe_load(File.read(config_file), aliases: true) config_hash = configurations[env] raise "Configuration[#{env}] NotFound" unless config_hash diff --git a/lib/version.rb b/lib/version.rb index 3729efb5a..e09e213b1 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -1,5 +1,5 @@ -# Copyright 2022 VMware, Inc. +# Copyright 2025 VMware, Inc. # SPDX-License-Identifier: EPL-2.0 - VERSION_INFO = [0, 2, 1].freeze + VERSION_INFO = [0, 8, 0].freeze VERSION = VERSION_INFO.map(&:to_s).join('.').freeze diff --git a/singleton-client.gemspec b/singleton-client.gemspec index 36fc8a7f9..8ebee13e5 100644 --- a/singleton-client.gemspec +++ b/singleton-client.gemspec @@ -17,11 +17,12 @@ Gem::Specification.new do |s| s.require_paths = ['lib'] s.add_dependency('concurrent-ruby') - s.add_dependency('faraday') - s.add_dependency('faraday_middleware') + s.add_dependency 'faraday', '~> 2.7' + s.add_dependency 'faraday-gzip', '~> 3' s.add_dependency('i18n') s.add_dependency('logging') s.add_dependency('multi_json') # TODO + s.add_dependency 'observer' s.add_dependency('request_store') s.add_dependency('twitter_cldr') diff --git a/spec/loader/mix_spec.rb b/spec/loader/mix_spec.rb index fc805f2a7..a208f6b6c 100644 --- a/spec/loader/mix_spec.rb +++ b/spec/loader/mix_spec.rb @@ -1,4 +1,4 @@ -# Copyright 2022 VMware, Inc. +# Copyright 2025 VMware, Inc. # SPDX-License-Identifier: EPL-2.0 describe 'Mix', :include_helpers, :extend_helpers do @@ -91,8 +91,8 @@ end it "get '#{en_locale}' translation - (get #{latest_locale} actually)" do - latest_response = File.new("spec/fixtures/mock_responses/#{component_only_on_server}-#{latest_locale}") - stubs << stub_request(:get, format(bundle_url, latest_locale, component_only_on_server)).to_return(body: latest_response) + latest_response = File.new("spec/fixtures/mock_responses/#{component_only_on_server}-#{latest_locale}").read + stubs << stub_request(:get, format(bundle_url, latest_locale, component_only_on_server)).to_return_json(body: latest_response) result = loader.get_bundle(component_only_on_server, en_locale) @@ -102,12 +102,12 @@ end it "should be able to get #{locale} translation" do - latest_response = File.new("spec/fixtures/mock_responses/#{component_only_on_server}-#{latest_locale}") - stubs << stub_request(:get, format(bundle_url, latest_locale, component_only_on_server)).to_return(body: latest_response) - en_response = File.new("spec/fixtures/mock_responses/#{component_only_on_server}-#{en_locale}") - stubs << stub_request(:get, format(bundle_url, en_locale, component_only_on_server)).to_return(body: en_response) - zh_response = File.new("spec/fixtures/mock_responses/#{component_only_on_server}-#{locale}") - stubs << stub_request(:get, format(bundle_url, locale, component_only_on_server)).to_return(body: zh_response) + latest_response = File.new("spec/fixtures/mock_responses/#{component_only_on_server}-#{latest_locale}").read + stubs << stub_request(:get, format(bundle_url, latest_locale, component_only_on_server)).to_return_json(body: latest_response) + en_response = File.new("spec/fixtures/mock_responses/#{component_only_on_server}-#{en_locale}").read + stubs << stub_request(:get, format(bundle_url, en_locale, component_only_on_server)).to_return_json(body: en_response) + zh_response = File.new("spec/fixtures/mock_responses/#{component_only_on_server}-#{locale}").read + stubs << stub_request(:get, format(bundle_url, locale, component_only_on_server)).to_return_json(body: zh_response) result = loader.get_bundle(component_only_on_server, locale) @@ -118,9 +118,9 @@ end it "should return nil for #{component_nonexistent}" do - # stubs << stub_request(:get, format(bundle_url, en_locale, component_nonexistent)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, latest_locale, component_nonexistent)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, locale, component_nonexistent)).to_return(body: nonexistent_response) + # stubs << stub_request(:get, format(bundle_url, en_locale, component_nonexistent)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, latest_locale, component_nonexistent)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, locale, component_nonexistent)).to_return_json(body: nonexistent_response) expect { loader.get_bundle(component_nonexistent, locale) }.to raise_error(SgtnClient::SingletonError) @@ -129,9 +129,9 @@ end it "should return nil for #{locale_nonexistent}" do - stubs << stub_request(:get, format(bundle_url, latest_locale, component)).to_return(body: nonexistent_response) - # stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, locale_nonexistent, component)).to_return(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, latest_locale, component)).to_return_json(body: nonexistent_response) + # stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, locale_nonexistent, component)).to_return_json(body: nonexistent_response) expect { loader.get_bundle(component, locale_nonexistent) }.to raise_error(SgtnClient::SingletonError) @@ -167,10 +167,10 @@ end it "should be able to get #{locale}" do - zh_response = File.new("spec/fixtures/mock_responses/#{component}-#{locale}") - stubs << stub_request(:get, format(bundle_url, locale, component)).to_return(body: zh_response) - en_response = File.new("spec/fixtures/mock_responses/#{component}-#{en_locale}") - stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return(body: en_response) + zh_response = File.new("spec/fixtures/mock_responses/#{component}-#{locale}").read + stubs << stub_request(:get, format(bundle_url, locale, component)).to_return_json(body: zh_response) + en_response = File.new("spec/fixtures/mock_responses/#{component}-#{en_locale}").read + stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return_json(body: en_response) result = loader.get_bundle(component, locale) @@ -180,7 +180,7 @@ end it 'fallback to server when a component is unavailable in local source' do - stubs << stub_request(:get, format(bundle_url, latest_locale, component_only_on_server)).to_return(body: stub_response("#{component_only_on_server}-#{latest_locale}")) + stubs << stub_request(:get, format(bundle_url, latest_locale, component_only_on_server)).to_return_json(body: stub_response("#{component_only_on_server}-#{latest_locale}")) result = loader.get_bundle(component_only_on_server, en_locale) expect(result[message_only_on_server_key]).to eq 'Message only on server' @@ -189,9 +189,9 @@ end it "should return nil for #{component_nonexistent}" do - # stubs << stub_request(:get, format(bundle_url, en_locale, component_nonexistent)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, latest_locale, component_nonexistent)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, locale, component_nonexistent)).to_return(body: nonexistent_response) + # stubs << stub_request(:get, format(bundle_url, en_locale, component_nonexistent)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, latest_locale, component_nonexistent)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, locale, component_nonexistent)).to_return_json(body: nonexistent_response) expect { loader.get_bundle(component_nonexistent, locale) }.to raise_error(SgtnClient::SingletonError) @@ -200,8 +200,8 @@ end it "should return nil for #{locale_nonexistent}" do - # stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, locale_nonexistent, component)).to_return(body: nonexistent_response) + # stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, locale_nonexistent, component)).to_return_json(body: nonexistent_response) expect { loader.get_bundle(component, locale_nonexistent) }.to raise_error(SgtnClient::SingletonError) @@ -223,7 +223,7 @@ end it 'should be able to get En' do - stubs << stub_request(:get, format(bundle_url, latest_locale, component)).to_return(body: stub_response("#{component}-#{latest_locale}")) + stubs << stub_request(:get, format(bundle_url, latest_locale, component)).to_return_json(body: stub_response("#{component}-#{latest_locale}")) result = loader.get_bundle(component, en_locale) @@ -233,9 +233,9 @@ end it "should be able to get #{locale}" do - stubs << stub_request(:get, format(bundle_url, latest_locale, component)).to_return(body: stub_response("#{component}-#{latest_locale}")) - stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return(body: stub_response("#{component}-#{en_locale}")) - stubs << stub_request(:get, format(bundle_url, locale, component)).to_return(body: stub_response("#{component}-#{locale}")) + stubs << stub_request(:get, format(bundle_url, latest_locale, component)).to_return_json(body: stub_response("#{component}-#{latest_locale}")) + stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return_json(body: stub_response("#{component}-#{en_locale}")) + stubs << stub_request(:get, format(bundle_url, locale, component)).to_return_json(body: stub_response("#{component}-#{locale}")) result = loader.get_bundle(component, locale) @@ -247,9 +247,9 @@ it 'should NOT fallback old SOURCE from remote to local when doing source comparison' do local_translation = Sgtn.config.loader.loaders.filter { |v| v.is_a?(SgtnClient::TranslationLoader::LocalTranslation) } expect(local_translation).to_not receive(:load_bundle) - stubs << stub_request(:get, format(bundle_url, latest_locale, component)).to_return(body: stub_response("#{component}-#{latest_locale}")) - stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, locale, component)).to_return(body: stub_response("#{component}-#{locale}")) + stubs << stub_request(:get, format(bundle_url, latest_locale, component)).to_return_json(body: stub_response("#{component}-#{latest_locale}")) + stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, locale, component)).to_return_json(body: stub_response("#{component}-#{locale}")) result = loader.get_bundle(component, locale) @@ -261,7 +261,7 @@ end it '#raise exception when querying En and there is no latest_locale bundle on both server and local translations' do - stubs << stub_request(:get, format(bundle_url, latest_locale, component_local_source_only)).to_return(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, latest_locale, component_local_source_only)).to_return_json(body: nonexistent_response) expect { loader.get_bundle(component_local_source_only, en_locale) }.to raise_error(Errno::ENOENT) @@ -269,7 +269,7 @@ end it "should be able to fallback to local latest for SOURCE locale - #{en_locale}" do - stubs << stub_request(:get, format(bundle_url, latest_locale, component_local_translation_only)).to_return(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, latest_locale, component_local_translation_only)).to_return_json(body: nonexistent_response) result = loader.get_bundle(component_local_translation_only, en_locale) @@ -279,9 +279,9 @@ end it "should be able to fallback to local translation for #{locale}" do - stubs << stub_request(:get, format(bundle_url, latest_locale, component_local_translation_only)).to_return(body: nonexistent_response) - # stubs << stub_request(:get, format(bundle_url, en_locale, component_local_translation_only)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, locale, component_local_translation_only)).to_return(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, latest_locale, component_local_translation_only)).to_return_json(body: nonexistent_response) + # stubs << stub_request(:get, format(bundle_url, en_locale, component_local_translation_only)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, locale, component_local_translation_only)).to_return_json(body: nonexistent_response) result = loader.get_bundle(component_local_translation_only, locale) @@ -291,9 +291,9 @@ end it "should return nil for #{component_nonexistent}" do - stubs << stub_request(:get, format(bundle_url, latest_locale, component_nonexistent)).to_return(body: nonexistent_response) - # stubs << stub_request(:get, format(bundle_url, en_locale, component_nonexistent)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, locale, component_nonexistent)).to_return(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, latest_locale, component_nonexistent)).to_return_json(body: nonexistent_response) + # stubs << stub_request(:get, format(bundle_url, en_locale, component_nonexistent)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, locale, component_nonexistent)).to_return_json(body: nonexistent_response) expect { loader.get_bundle(component_nonexistent, locale) }.to raise_error(Errno::ENOENT) @@ -302,9 +302,9 @@ end it "should return nil for #{locale_nonexistent}" do - stubs << stub_request(:get, format(bundle_url, latest_locale, component)).to_return(body: nonexistent_response) - # stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, locale_nonexistent, component)).to_return(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, latest_locale, component)).to_return_json(body: nonexistent_response) + # stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, locale_nonexistent, component)).to_return_json(body: nonexistent_response) expect { loader.get_bundle(component, locale_nonexistent) }.to raise_error(Errno::ENOENT) @@ -379,10 +379,10 @@ end it "#{locale} should use translation from server" do - en_response = File.new("spec/fixtures/mock_responses/#{component}-#{en_locale}") - stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return(body: en_response) - zh_response = File.new("spec/fixtures/mock_responses/#{component}-#{locale}") - stubs << stub_request(:get, format(bundle_url, locale, component)).to_return(body: zh_response) + en_response = File.new("spec/fixtures/mock_responses/#{component}-#{en_locale}").read + stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return_json(body: en_response) + zh_response = File.new("spec/fixtures/mock_responses/#{component}-#{locale}").read + stubs << stub_request(:get, format(bundle_url, locale, component)).to_return_json(body: zh_response) result = loader.get_bundle(component, locale) @@ -392,9 +392,9 @@ end it "should be able to fallback to local translation for #{locale}" do - stubs << stub_request(:get, format(bundle_url, latest_locale, component_local_translation_only)).to_return(body: nonexistent_response) - # stubs << stub_request(:get, format(bundle_url, en_locale, component_local_translation_only)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, locale, component_local_translation_only)).to_return(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, latest_locale, component_local_translation_only)).to_return_json(body: nonexistent_response) + # stubs << stub_request(:get, format(bundle_url, en_locale, component_local_translation_only)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, locale, component_local_translation_only)).to_return_json(body: nonexistent_response) result = loader.get_bundle(component_local_translation_only, locale) @@ -404,7 +404,7 @@ end it 'source bundle fallback to server when a component is unavailable in local source' do - stubs << stub_request(:get, format(bundle_url, latest_locale, component_only_on_server)).to_return(body: stub_response("#{component_only_on_server}-#{latest_locale}")) + stubs << stub_request(:get, format(bundle_url, latest_locale, component_only_on_server)).to_return_json(body: stub_response("#{component_only_on_server}-#{latest_locale}")) result = loader.get_bundle(component_only_on_server, en_locale) expect(result[message_only_on_server_key]).to eq 'Message only on server' @@ -413,9 +413,9 @@ end it "fallback latest from remote to local when querying #{locale}" do - # stubs << stub_request(:get, format(bundle_url, latest_locale, component)).to_return(body: stub_response("#{component}-#{latest_locale}")) - stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return(body: stub_response("#{component}-#{en_locale}")) - stubs << stub_request(:get, format(bundle_url, locale, component)).to_return(body: stub_response("#{component}-#{locale}")) + # stubs << stub_request(:get, format(bundle_url, latest_locale, component)).to_return_json(body: stub_response("#{component}-#{latest_locale}")) + stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return_json(body: stub_response("#{component}-#{en_locale}")) + stubs << stub_request(:get, format(bundle_url, locale, component)).to_return_json(body: stub_response("#{component}-#{locale}")) result = loader.get_bundle(component, locale) @@ -425,8 +425,8 @@ end it "fallback translation from remote to local when querying #{locale}" do - # stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return(body: stub_response("#{component}-#{en_locale}")) - stubs << stub_request(:get, format(bundle_url, locale, component)).to_return(body: nonexistent_response) + # stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return_json(body: stub_response("#{component}-#{en_locale}")) + stubs << stub_request(:get, format(bundle_url, locale, component)).to_return_json(body: nonexistent_response) result = loader.get_bundle(component, locale) @@ -436,9 +436,9 @@ end it "should return nil for #{component_nonexistent}" do - stubs << stub_request(:get, format(bundle_url, latest_locale, component_nonexistent)).to_return(body: nonexistent_response) - # stubs << stub_request(:get, format(bundle_url, en_locale, component_nonexistent)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, locale, component_nonexistent)).to_return(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, latest_locale, component_nonexistent)).to_return_json(body: nonexistent_response) + # stubs << stub_request(:get, format(bundle_url, en_locale, component_nonexistent)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, locale, component_nonexistent)).to_return_json(body: nonexistent_response) expect { loader.get_bundle(component_nonexistent, locale) }.to raise_error(Errno::ENOENT) @@ -447,8 +447,8 @@ end it "should raise exception for #{locale_nonexistent}" do - # stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return(body: nonexistent_response) - stubs << stub_request(:get, format(bundle_url, locale_nonexistent, component)).to_return(body: nonexistent_response) + # stubs << stub_request(:get, format(bundle_url, en_locale, component)).to_return_json(body: nonexistent_response) + stubs << stub_request(:get, format(bundle_url, locale_nonexistent, component)).to_return_json(body: nonexistent_response) expect { loader.get_bundle(component, locale_nonexistent) }.to raise_error(Errno::ENOENT) diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index fb195d40d..8db88616b 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2022 VMware, Inc. +# Copyright 2025 VMware, Inc. # SPDX-License-Identifier: EPL-2.0 require 'active_support' @@ -75,19 +75,19 @@ def source_path self.defaut_value = 'defaut value' def components_stub - stub_request(:get, components_url).to_return(body: File.new('spec/fixtures/mock_responses/componentlist')) + stub_request(:get, components_url).to_return_json(body: File.new('spec/fixtures/mock_responses/componentlist').read) end def locales_stub - stub_request(:get, locales_url).to_return(body: File.new('spec/fixtures/mock_responses/localelist')) + stub_request(:get, locales_url).to_return_json(body: File.new('spec/fixtures/mock_responses/localelist').read) end def bundle_stub(component, locale, response) - stub_request(:get, format(bundle_url, locale, component)).to_return(body: response) + stub_request(:get, format(bundle_url, locale, component)).to_return_json(body: response) end def stub_response(file_name) - File.new("spec/fixtures/mock_responses/#{file_name}") + File.new("spec/fixtures/mock_responses/#{file_name}").read end def nonexistent_response diff --git a/spec/support/sample_data.rb b/spec/support/sample_data.rb index 54b756a55..b82d4d5ab 100644 --- a/spec/support/sample_data.rb +++ b/spec/support/sample_data.rb @@ -1,5 +1,8 @@ +# Copyright 2025 VMware, Inc. +# SPDX-License-Identifier: EPL-2.0 + module SampleData def samples - @@samples ||= YAML.load(File.read(File.expand_path("../../config/sample_data.yml", __FILE__))) + @@samples ||= YAML.safe_load(File.read(File.expand_path("../../config/sample_data.yml", __FILE__))) end end