From e3cf754e3ad348843041091ba2e41f6306c29443 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Thu, 23 Mar 2023 14:51:04 +0530 Subject: [PATCH 01/14] updated the .properties and yml file for sonarQube Signed-off-by: nikhil2611 --- .github/workflows/sonarqube.yml | 33 +++++++++++++++++++++++++++++++++ sonar-project.properties | 21 +++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .github/workflows/sonarqube.yml create mode 100644 sonar-project.properties diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml new file mode 100644 index 00000000..e2fbb22e --- /dev/null +++ b/.github/workflows/sonarqube.yml @@ -0,0 +1,33 @@ +name: SonarQube scan +on: + # Trigger analysis when pushing to your main branches, and when creating a pull request. + push: + branches: + - main # or the name of your main branch + - develop + - 'release/**' + pull_request: + types: [opened, synchronize, reopened] + +jobs: + sonarqube: + runs-on: ip-range-controlled +# needs: [build] + steps: + - uses: actions/checkout@v3 + with: + # Disabling shallow clone is recommended for improving relevancy of reporting + fetch-depth: 0 + - name: SonarQube Scan + uses: sonarsource/sonarqube-scan-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + # If you wish to fail your job when the Quality Gate is red, uncomment the + # following lines. This would typically be used to fail a deployment. + # We do not recommend to use this in a pull request. Prefer using pull request + # decoration instead. + # - uses: sonarsource/sonarqube-quality-gate-action@master + # timeout-minutes: 5 + # env: + # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..81ec28ed --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,21 @@ +# must be unique in a given SonarQube instance +sonar.projectKey=chef_chef-cli_AYcNv4diJ4YHsO5MtJHg + +sonar.projectName=chef-cli + +# defaults to 'not provided' +#sonar.projectVersion=1.0 + +sonar.sources=. +sonar.exclusions=**/*_test.go + +sonar.tests=. +sonar.test.inclusions=**/*_test.go + +# Encoding of the source code. Default is default system encoding +#sonar.sourceEncoding=UTF-8 + +# skip C-language processor +sonar.c.file.suffixes=- +sonar.cpp.file.suffixes=- +sonar.objc.file.suffixes=- \ No newline at end of file From bdf98e643969981ba6bc73a746c2cbaf8c2b929c Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Wed, 10 Jul 2024 16:41:31 +0530 Subject: [PATCH 02/14] added verify pipeline for ruby 3.3 Signed-off-by: nikhil2611 --- .expeditor/verify.pipeline.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index d4c15cf3..25387d3c 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -27,6 +27,14 @@ steps: docker: image: ruby:3.0 +- label: run-specs-ruby-3.3 + command: + - .expeditor/run_linux_tests.sh rspec + expeditor: + executor: + docker: + image: ruby:3.3 + - label: run-specs-windows-2.7 command: - powershell .expeditor/run_windows_tests.ps1 rspec @@ -54,6 +62,14 @@ steps: docker: image: ruby:2.7 +- label: cookstyle-generator-cb-tests-ruby-3.3 + command: + - .expeditor/run_linux_tests.sh "rake style:cookstyle" + expeditor: + executor: + docker: + image: ruby:3.3 + - label: chefstyle-tests-ruby-2.7 command: - .expeditor/run_linux_tests.sh "rake style:chefstyle" @@ -61,3 +77,11 @@ steps: executor: docker: image: ruby:2.7 + +- label: chefstyle-tests-ruby-3.3 + command: + - .expeditor/run_linux_tests.sh "rake style:chefstyle" + expeditor: + executor: + docker: + image: ruby:3.3 From e4ee19d4935c5c233e36f50022b3fd33da272b8b Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Wed, 10 Jul 2024 16:51:03 +0530 Subject: [PATCH 03/14] removed the ruby 2.7 and 3.0 pipeline Signed-off-by: nikhil2611 --- .expeditor/verify.pipeline.yml | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index 25387d3c..6937f331 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -11,22 +11,6 @@ expeditor: steps: -- label: run-specs-ruby-2.7 - command: - - .expeditor/run_linux_tests.sh rspec - expeditor: - executor: - docker: - image: ruby:2.7 - -- label: run-specs-ruby-3.0 - command: - - .expeditor/run_linux_tests.sh rspec - expeditor: - executor: - docker: - image: ruby:3.0 - - label: run-specs-ruby-3.3 command: - .expeditor/run_linux_tests.sh rspec @@ -54,14 +38,6 @@ steps: shell: ["powershell", "-Command"] image: rubydistros/windows-2019:3.0 -- label: cookstyle-generator-cb-tests-ruby-2.7 - command: - - .expeditor/run_linux_tests.sh "rake style:cookstyle" - expeditor: - executor: - docker: - image: ruby:2.7 - - label: cookstyle-generator-cb-tests-ruby-3.3 command: - .expeditor/run_linux_tests.sh "rake style:cookstyle" @@ -70,14 +46,6 @@ steps: docker: image: ruby:3.3 -- label: chefstyle-tests-ruby-2.7 - command: - - .expeditor/run_linux_tests.sh "rake style:chefstyle" - expeditor: - executor: - docker: - image: ruby:2.7 - - label: chefstyle-tests-ruby-3.3 command: - .expeditor/run_linux_tests.sh "rake style:chefstyle" From 2547dbd682f7613ff4a683ca19f473a1a64f0407 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Wed, 10 Jul 2024 16:57:22 +0530 Subject: [PATCH 04/14] updated HTTPServerException to HTTPClientException Signed-off-by: nikhil2611 --- spec/unit/policyfile_services/clean_policies_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/policyfile_services/clean_policies_spec.rb b/spec/unit/policyfile_services/clean_policies_spec.rb index 6c8a010e..6d462fc2 100644 --- a/spec/unit/policyfile_services/clean_policies_spec.rb +++ b/spec/unit/policyfile_services/clean_policies_spec.rb @@ -215,7 +215,7 @@ # this will continue to print that out until they remove HTTPServerException expected_message = <<~ERROR Failed to delete some policy revisions: - - appserver (4444444444444444444444444444444444444444444444444444444444444444): Net::HTTPServerException 403 \"Unauthorized\" + - appserver (4444444444444444444444444444444444444444444444444444444444444444): Net::HTTPClientException 403 \"Unauthorized\" ERROR expect { clean_policies_service.run }.to raise_error do |error| From 02c692880b9c33c99c763e79c6b602ca371ae5f3 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Thu, 11 Jul 2024 17:24:04 +0530 Subject: [PATCH 05/14] fixing test-cases Signed-off-by: nikhil2611 --- .expeditor/verify.pipeline.yml | 9 --------- spec/unit/command/generator_commands/repo_spec.rb | 2 +- .../chefignore | 0 3 files changed, 1 insertion(+), 10 deletions(-) create mode 100644 spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index 6937f331..8f9639d9 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -19,15 +19,6 @@ steps: docker: image: ruby:3.3 -- label: run-specs-windows-2.7 - command: - - powershell .expeditor/run_windows_tests.ps1 rspec - expeditor: - executor: - docker: - host_os: windows - image: rubydistros/windows-2019:2.7 - - label: run-specs-windows-ruby-3.0 command: - powershell .expeditor/run_windows_tests.ps1 rspec diff --git a/spec/unit/command/generator_commands/repo_spec.rb b/spec/unit/command/generator_commands/repo_spec.rb index 86499b83..77fec47e 100644 --- a/spec/unit/command/generator_commands/repo_spec.rb +++ b/spec/unit/command/generator_commands/repo_spec.rb @@ -256,7 +256,7 @@ def generator_context let(:file) { "cookbooks/example/recipes/default.rb" } it "has the right contents" do - expect(file_contents).to match(/log "Welcome to Chef Infra Client, \#\{node\['example'\]\['name'\]\}!" do/) + expect(file_contents).to match(/log "Welcome to Chef Infra Client, \#\{node\["example"\]\["name"\]\}!" do/) end end end diff --git a/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore b/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore new file mode 100644 index 00000000..e69de29b From c0877b4f4998889608d8720231d2d634a34c0968 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Fri, 12 Jul 2024 02:12:38 +0530 Subject: [PATCH 06/14] updated gem versions Signed-off-by: nikhil2611 --- Gemfile | 15 ++++++--------- .../repo/cookbooks/example/recipes/default.rb | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index b6918aaa..6631c114 100644 --- a/Gemfile +++ b/Gemfile @@ -7,17 +7,14 @@ group :test do gem "rspec", "~> 3.8" gem "rspec-expectations", "~> 3.8" gem "rspec-mocks", "~> 3.8" - gem "cookstyle", "=7.7.2" # this forces dependabot PRs to open which triggers cookstyle CI on the chef generate command - gem "chefstyle", "=1.6.2" + gem "cookstyle", "=7.32.2" # this forces dependabot PRs to open which triggers cookstyle CI on the chef generate command + gem "chefstyle", "=2.2.3" gem "test-kitchen", "=3.5.1" # pinning test-kitchen to 3.5.1 which supports ruby < 3.1 . Need to update this to latest once we update the ruby to 3.1 and chef to 18.x in chef-cli - if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6") - gem "chef-zero", "~> 14" - gem "chef", "~> 15" - gem "chef-utils", "=16.6.14" - end - if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7") - gem "ohai", "~> 16" + if RUBY_VERSION.match?(/3.1/) + gem.add_dependency "chef", "~> 18.0" + else + gem.add_dependency "chef", ">= 16.0" end gem "simplecov", require: false diff --git a/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb b/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb index e3f5f0e1..ed33d084 100644 --- a/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb +++ b/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb @@ -1,7 +1,7 @@ # This is a Chef Infra Client recipe file. It can be used to specify resources # which will apply configuration to a server. -log "Welcome to Chef Infra Client, #{node['example']['name']}!" do +log log "Welcome to Chef Infra Client, #{node["example"]["name"]}!" do level :info end From 0839e8e96845a84d41492531587b988d5b66c315 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Fri, 12 Jul 2024 02:20:17 +0530 Subject: [PATCH 07/14] typ Signed-off-by: nikhil2611 --- Gemfile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 6631c114..f23172d9 100644 --- a/Gemfile +++ b/Gemfile @@ -11,10 +11,13 @@ group :test do gem "chefstyle", "=2.2.3" gem "test-kitchen", "=3.5.1" # pinning test-kitchen to 3.5.1 which supports ruby < 3.1 . Need to update this to latest once we update the ruby to 3.1 and chef to 18.x in chef-cli - if RUBY_VERSION.match?(/3.1/) - gem.add_dependency "chef", "~> 18.0" - else - gem.add_dependency "chef", ">= 16.0" + if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6") + gem "chef-zero", "~> 14" + gem "chef", "~> 15" + gem "chef-utils", "=16.6.14" + end + if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7") + gem "ohai", "~> 16" end gem "simplecov", require: false From 44ffb25c27f457bc35bd5159195da9d95915594d Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Fri, 12 Jul 2024 02:26:21 +0530 Subject: [PATCH 08/14] added win ruby 3.1 pipeline Signed-off-by: nikhil2611 --- .expeditor/verify.pipeline.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index 8f9639d9..d845d375 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -19,7 +19,7 @@ steps: docker: image: ruby:3.3 -- label: run-specs-windows-ruby-3.0 +- label: run-specs-windows-ruby-3.3 command: - powershell .expeditor/run_windows_tests.ps1 rspec expeditor: @@ -27,7 +27,7 @@ steps: docker: host_os: windows shell: ["powershell", "-Command"] - image: rubydistros/windows-2019:3.0 + image: rubydistros/windows-2019:3.3 - label: cookstyle-generator-cb-tests-ruby-3.3 command: From 7b859e968258de762c111e850d8b7cdb066fbaa0 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Fri, 12 Jul 2024 11:14:40 +0530 Subject: [PATCH 09/14] updated test cases Signed-off-by: nikhil2611 --- chef-cli.gemspec | 2 +- .../policyfile/artifactory_cookbook_source.rb | 12 ++++---- .../policyfile/chef_server_cookbook_source.rb | 16 ++++------ .../policyfile/community_cookbook_source.rb | 12 ++++---- .../policyfile/delivery_supermarket_source.rb | 14 ++++----- .../policyfile_location_specification.rb | 30 ++++++++----------- .../policyfile_services/export_repo.rb | 12 ++++---- .../provisioner/chef_zero_capture_spec.rb | 8 ++--- spec/unit/policyfile/comparison_base_spec.rb | 20 ++++++------- .../clean_policies_spec.rb | 21 ++++++------- .../clean_policy_cookbooks_spec.rb | 10 +++---- .../policyfile_services/push_archive_spec.rb | 14 ++++----- .../rm_policy_group_spec.rb | 10 +++---- .../policyfile_services/rm_policy_spec.rb | 20 ++++++------- .../policyfile_services/show_policy_spec.rb | 20 ++++++------- .../unit/policyfile_services/undelete_spec.rb | 10 +++---- 16 files changed, 109 insertions(+), 122 deletions(-) diff --git a/chef-cli.gemspec b/chef-cli.gemspec index 2badc276..a56f84f9 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -43,7 +43,7 @@ Gem::Specification.new do |gem| gem.add_dependency "mixlib-shellout", ">= 2.0", "< 4.0" gem.add_dependency "ffi-yajl", ">= 1.0", "< 3.0" gem.add_dependency "minitar", "~> 0.6" - if RUBY_VERSION.match?(/3.1/) + if RUBY_VERSION.match?(/3.3/) gem.add_dependency "chef", "~> 18.0" else gem.add_dependency "chef", "~> 17.0" diff --git a/lib/chef-cli/policyfile/artifactory_cookbook_source.rb b/lib/chef-cli/policyfile/artifactory_cookbook_source.rb index f3bc20f9..0e838560 100644 --- a/lib/chef-cli/policyfile/artifactory_cookbook_source.rb +++ b/lib/chef-cli/policyfile/artifactory_cookbook_source.rb @@ -54,14 +54,12 @@ def preferred_source_for?(cookbook_name) end def universe_graph - @universe_graph ||= begin - full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| - normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| - deps_by_version[version] = metadata["dependencies"] - deps_by_version - end - normalized_graph + @universe_graph ||= full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| + normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| + deps_by_version[version] = metadata["dependencies"] + deps_by_version end + normalized_graph end end diff --git a/lib/chef-cli/policyfile/chef_server_cookbook_source.rb b/lib/chef-cli/policyfile/chef_server_cookbook_source.rb index b08453e8..f898375c 100644 --- a/lib/chef-cli/policyfile/chef_server_cookbook_source.rb +++ b/lib/chef-cli/policyfile/chef_server_cookbook_source.rb @@ -52,14 +52,12 @@ def preferred_source_for?(cookbook_name) end def universe_graph - @universe_graph ||= begin - full_chef_server_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| - normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| - deps_by_version[version] = metadata["dependencies"] - deps_by_version - end - normalized_graph + @universe_graph ||= full_chef_server_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| + normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| + deps_by_version[version] = metadata["dependencies"] + deps_by_version end + normalized_graph end end @@ -90,9 +88,7 @@ def http_connection_for(base_url) def full_chef_server_graph @full_chef_server_graph ||= - begin - http_connection_for(uri.to_s).get("/universe") - end + http_connection_for(uri.to_s).get("/universe") end end end diff --git a/lib/chef-cli/policyfile/community_cookbook_source.rb b/lib/chef-cli/policyfile/community_cookbook_source.rb index 56620a81..e637f89d 100644 --- a/lib/chef-cli/policyfile/community_cookbook_source.rb +++ b/lib/chef-cli/policyfile/community_cookbook_source.rb @@ -52,14 +52,12 @@ def ==(other) end def universe_graph - @universe_graph ||= begin - full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| - normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| - deps_by_version[version] = metadata["dependencies"] - deps_by_version - end - normalized_graph + @universe_graph ||= full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| + normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| + deps_by_version[version] = metadata["dependencies"] + deps_by_version end + normalized_graph end end diff --git a/lib/chef-cli/policyfile/delivery_supermarket_source.rb b/lib/chef-cli/policyfile/delivery_supermarket_source.rb index 165f7886..db64d67e 100644 --- a/lib/chef-cli/policyfile/delivery_supermarket_source.rb +++ b/lib/chef-cli/policyfile/delivery_supermarket_source.rb @@ -66,15 +66,13 @@ def default_source_args end def universe_graph - @universe_graph ||= begin - @community_source.universe_graph.inject({}) do |truncated, (cookbook_name, version_and_deps_list)| - sorted_versions = version_and_deps_list.keys.sort_by do |version_string| - Semverse::Version.new(version_string) - end - greatest_version = sorted_versions.last - truncated[cookbook_name] = { greatest_version => version_and_deps_list[greatest_version] } - truncated + @universe_graph ||= @community_source.universe_graph.inject({}) do |truncated, (cookbook_name, version_and_deps_list)| + sorted_versions = version_and_deps_list.keys.sort_by do |version_string| + Semverse::Version.new(version_string) end + greatest_version = sorted_versions.last + truncated[cookbook_name] = { greatest_version => version_and_deps_list[greatest_version] } + truncated end end diff --git a/lib/chef-cli/policyfile/policyfile_location_specification.rb b/lib/chef-cli/policyfile/policyfile_location_specification.rb index 91ea19bd..af5aa5bb 100644 --- a/lib/chef-cli/policyfile/policyfile_location_specification.rb +++ b/lib/chef-cli/policyfile/policyfile_location_specification.rb @@ -62,20 +62,18 @@ def revision_id # @return A policyfile lock fetcher compatible with the given source_options def fetcher - @fetcher ||= begin - if source_options[:path] && !source_options[:git] - Policyfile::LocalLockFetcher.new(name, source_options, storage_config) - elsif source_options[:remote] - Policyfile::RemoteLockFetcher.new(name, source_options) - elsif source_options[:server] - Policyfile::ChefServerLockFetcher.new(name, source_options, chef_config) - elsif source_options[:git] - Policyfile::GitLockFetcher.new(name, source_options, storage_config) - else - raise ChefCLI::InvalidPolicyfileLocation.new( - "Invalid policyfile lock location type. The supported locations are: #{LOCATION_TYPES.join(", ")}" - ) - end + @fetcher ||= if source_options[:path] && !source_options[:git] + Policyfile::LocalLockFetcher.new(name, source_options, storage_config) + elsif source_options[:remote] + Policyfile::RemoteLockFetcher.new(name, source_options) + elsif source_options[:server] + Policyfile::ChefServerLockFetcher.new(name, source_options, chef_config) + elsif source_options[:git] + Policyfile::GitLockFetcher.new(name, source_options, storage_config) + else + raise ChefCLI::InvalidPolicyfileLocation.new( + "Invalid policyfile lock location type. The supported locations are: #{LOCATION_TYPES.join(", ")}" + ) end end @@ -106,9 +104,7 @@ def errors # # @return [PolicyfileLock] the loaded policyfile lock def policyfile_lock - @policyfile_lock ||= begin - PolicyfileLock.new(storage_config, ui: ui).build_from_lock_data(fetcher.lock_data) - end + @policyfile_lock ||= PolicyfileLock.new(storage_config, ui: ui).build_from_lock_data(fetcher.lock_data) end # @return [Hash] The source_options that describe how to fetch this exact lock again diff --git a/lib/chef-cli/policyfile_services/export_repo.rb b/lib/chef-cli/policyfile_services/export_repo.rb index 70ff6955..56930b79 100644 --- a/lib/chef-cli/policyfile_services/export_repo.rb +++ b/lib/chef-cli/policyfile_services/export_repo.rb @@ -121,12 +121,12 @@ def with_staging_dir random_string = SecureRandom.hex(2) path = "chef-export-#{random_string}" Dir.mktmpdir(path) do |d| - begin - @staging_dir = d - yield - ensure - @staging_dir = nil - end + + @staging_dir = d + yield + ensure + @staging_dir = nil + end end diff --git a/spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb b/spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb index ace053ba..671a742c 100644 --- a/spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb +++ b/spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb @@ -60,10 +60,10 @@ end after do - begin - subject.cleanup_sandbox - rescue # rubocop:disable Lint/HandleExceptions - end + + subject.cleanup_sandbox + rescue # rubocop:disable Lint/HandleExceptions + end end diff --git a/spec/unit/policyfile/comparison_base_spec.rb b/spec/unit/policyfile/comparison_base_spec.rb index d11b4f98..33c2f329 100644 --- a/spec/unit/policyfile/comparison_base_spec.rb +++ b/spec/unit/policyfile/comparison_base_spec.rb @@ -251,11 +251,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do @@ -285,11 +285,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do diff --git a/spec/unit/policyfile_services/clean_policies_spec.rb b/spec/unit/policyfile_services/clean_policies_spec.rb index 6d462fc2..36bd78a5 100644 --- a/spec/unit/policyfile_services/clean_policies_spec.rb +++ b/spec/unit/policyfile_services/clean_policies_spec.rb @@ -46,11 +46,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do @@ -196,13 +196,14 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end + before do expect(http_client).to receive(:delete) .with("/policies/appserver/revisions/4444444444444444444444444444444444444444444444444444444444444444") diff --git a/spec/unit/policyfile_services/clean_policy_cookbooks_spec.rb b/spec/unit/policyfile_services/clean_policy_cookbooks_spec.rb index d3013310..7fd99602 100644 --- a/spec/unit/policyfile_services/clean_policy_cookbooks_spec.rb +++ b/spec/unit/policyfile_services/clean_policy_cookbooks_spec.rb @@ -103,11 +103,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do diff --git a/spec/unit/policyfile_services/push_archive_spec.rb b/spec/unit/policyfile_services/push_archive_spec.rb index 1310c4a3..85cb2bb8 100644 --- a/spec/unit/policyfile_services/push_archive_spec.rb +++ b/spec/unit/policyfile_services/push_archive_spec.rb @@ -129,13 +129,13 @@ def create_archive context "with an invalid archive" do let(:exception) do - begin - push_archive_service.run - rescue ChefCLI::PolicyfilePushArchiveError => e - e - else - nil - end + + push_archive_service.run + rescue ChefCLI::PolicyfilePushArchiveError => e + e + else + nil + end let(:exception_cause) { exception.cause } diff --git a/spec/unit/policyfile_services/rm_policy_group_spec.rb b/spec/unit/policyfile_services/rm_policy_group_spec.rb index 5dc71323..73cc32ee 100644 --- a/spec/unit/policyfile_services/rm_policy_group_spec.rb +++ b/spec/unit/policyfile_services/rm_policy_group_spec.rb @@ -93,11 +93,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do diff --git a/spec/unit/policyfile_services/rm_policy_spec.rb b/spec/unit/policyfile_services/rm_policy_spec.rb index 66e9771e..bb87f6e5 100644 --- a/spec/unit/policyfile_services/rm_policy_spec.rb +++ b/spec/unit/policyfile_services/rm_policy_spec.rb @@ -69,11 +69,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do @@ -108,11 +108,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do diff --git a/spec/unit/policyfile_services/show_policy_spec.rb b/spec/unit/policyfile_services/show_policy_spec.rb index e03fa43d..aa985c10 100644 --- a/spec/unit/policyfile_services/show_policy_spec.rb +++ b/spec/unit/policyfile_services/show_policy_spec.rb @@ -65,11 +65,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end let(:policies_url) { "/policies" } @@ -823,11 +823,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do diff --git a/spec/unit/policyfile_services/undelete_spec.rb b/spec/unit/policyfile_services/undelete_spec.rb index 1acddb37..02319bd7 100644 --- a/spec/unit/policyfile_services/undelete_spec.rb +++ b/spec/unit/policyfile_services/undelete_spec.rb @@ -185,11 +185,11 @@ def next_time end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do From fd2f091ca3da9d930d64b322e7c15cb540ce04e6 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Fri, 12 Jul 2024 11:21:36 +0530 Subject: [PATCH 10/14] removed extra spaces Signed-off-by: nikhil2611 --- spec/unit/policyfile_services/clean_policies_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/unit/policyfile_services/clean_policies_spec.rb b/spec/unit/policyfile_services/clean_policies_spec.rb index 36bd78a5..a4cf0dcd 100644 --- a/spec/unit/policyfile_services/clean_policies_spec.rb +++ b/spec/unit/policyfile_services/clean_policies_spec.rb @@ -203,7 +203,6 @@ end - before do expect(http_client).to receive(:delete) .with("/policies/appserver/revisions/4444444444444444444444444444444444444444444444444444444444444444") From 50d5f0e6f40bb2e594b4dc81cc168fdd374b17e5 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Sat, 13 Jul 2024 19:38:53 +0530 Subject: [PATCH 11/14] updated rspec version Signed-off-by: nikhil2611 --- Gemfile | 12 +----------- chef-cli.gemspec | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index f23172d9..387f98e3 100644 --- a/Gemfile +++ b/Gemfile @@ -4,22 +4,12 @@ gemspec group :test do gem "rake" - gem "rspec", "~> 3.8" + gem "rspec", "~> 3.12" gem "rspec-expectations", "~> 3.8" gem "rspec-mocks", "~> 3.8" gem "cookstyle", "=7.32.2" # this forces dependabot PRs to open which triggers cookstyle CI on the chef generate command gem "chefstyle", "=2.2.3" gem "test-kitchen", "=3.5.1" # pinning test-kitchen to 3.5.1 which supports ruby < 3.1 . Need to update this to latest once we update the ruby to 3.1 and chef to 18.x in chef-cli - - if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6") - gem "chef-zero", "~> 14" - gem "chef", "~> 15" - gem "chef-utils", "=16.6.14" - end - if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7") - gem "ohai", "~> 16" - end - gem "simplecov", require: false end diff --git a/chef-cli.gemspec b/chef-cli.gemspec index a56f84f9..b3a2c1a6 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -29,7 +29,7 @@ Gem::Specification.new do |gem| gem.license = "Apache-2.0" gem.homepage = "https://www.chef.io/" - gem.required_ruby_version = ">= 2.7" + gem.required_ruby_version = ">= 3.1" gem.files = %w{Rakefile LICENSE} + Dir.glob("Gemfile*") + # Includes Gemfile and locks From 85104aa8ee22c8403df4114900806e561673bc0e Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Sun, 14 Jul 2024 17:57:11 +0530 Subject: [PATCH 12/14] updated test data Signed-off-by: nikhil2611 --- spec/unit/policyfile_lock_serialization_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/policyfile_lock_serialization_spec.rb b/spec/unit/policyfile_lock_serialization_spec.rb index 2ebe433a..8abcb416 100644 --- a/spec/unit/policyfile_lock_serialization_spec.rb +++ b/spec/unit/policyfile_lock_serialization_spec.rb @@ -137,7 +137,7 @@ it "requires the values in named_run_lists to be valid run lists" do bad_named_run_lists = valid_lock_data.dup - bad_named_run_lists["named_run_lists"] = { "bad" => [ 42 ] } + bad_named_run_lists["named_run_lists"] = { "bad" => [ "42" ] } expect { lockfile.build_from_lock_data(bad_named_run_lists) }.to raise_error(ChefCLI::InvalidLockfile) end From 70650c80417590ec15c70632db69e4b6711a9515 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Mon, 22 Jul 2024 00:42:45 +0530 Subject: [PATCH 13/14] updated the unit.yml to 3.3 Signed-off-by: nikhil2611 --- .github/workflows/unit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 869dce15..a7a61cd5 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -17,10 +17,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up ruby 3.1 + - name: Set up ruby 3.3 uses: ruby/setup-ruby@v1 with: - ruby-version: 3.1 + ruby-version: 3.3 bundler-cache: true - name: run specs run: bundle exec rake spec --trace From 5677e3a8a856a51679e5c96687b57d0dd5cbbfd4 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Mon, 22 Jul 2024 12:59:30 +0530 Subject: [PATCH 14/14] updated the ruby to 3.3 in gemspec Signed-off-by: nikhil2611 --- chef-cli.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chef-cli.gemspec b/chef-cli.gemspec index b3a2c1a6..ba1c2b2d 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -29,7 +29,7 @@ Gem::Specification.new do |gem| gem.license = "Apache-2.0" gem.homepage = "https://www.chef.io/" - gem.required_ruby_version = ">= 3.1" + gem.required_ruby_version = ">= 3.3" gem.files = %w{Rakefile LICENSE} + Dir.glob("Gemfile*") + # Includes Gemfile and locks