From 7e1da7164e49d893f7a5cecffcb1bdf21f5c558c Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 29 Dec 2023 16:25:51 +0100 Subject: [PATCH 1/6] Use bundler-cache option of ruby/setup-ruby ruby/setup-ruby has caching built in and is guaranteed to be correct. --- .github/workflows/main.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index df8f332..29496f2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -55,19 +55,9 @@ jobs: PHP_TZ: "US/Eastern" steps: - uses: actions/checkout@v2 - - uses: ruby/setup-ruby@v1 # actions/setup-ruby@v1 + - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - - uses: actions/cache@v2 - with: - path: vendor/bundle - key: ${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }} - restore-keys: | - ${{ matrix.ruby }}-gems- - - name: Bundle install - run: | - gem list --silent -i bundler -v '~> 2' || gem install bundler -v '~> 2' --no-document - bundle config path vendor/bundle - bundle install --without development --jobs 4 --retry 3 + bundler-cache: true - name: Run tests run: bundle exec rspec ./spec/* From 24fd38e376c5d6f797f599cae2d53365fe8cab4a Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 29 Dec 2023 16:26:57 +0100 Subject: [PATCH 2/6] Update actions/checkout to v4 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 29496f2..96337eb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -54,7 +54,7 @@ jobs: ZBX_SERVER_HOST: zabbix-server PHP_TZ: "US/Eastern" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} From 33470ea33356a4a3cd7f953f39d5a478c3e5deb8 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 29 Dec 2023 16:28:44 +0100 Subject: [PATCH 3/6] Exclude the development group from CI --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 96337eb..9f4a868 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,8 @@ name: CI +env: + BUNDLE_WITHOUT: development + on: push: branches: From 58182b28800c17390b190fee5830215a14cd010a Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 29 Dec 2023 16:30:37 +0100 Subject: [PATCH 4/6] Replace $default-branch with the actual value The default-branch value is just a placeholder that GitHub doesn't actually implement. --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9f4a868..8994d0e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,12 +6,12 @@ env: on: push: branches: - - $default-branch + - master paths-ignore: - '**.md' pull_request: branches: - - $default-branch + - master paths-ignore: - '**.md' From 04bc5416f5230c50224964ffb001c859d357fdd6 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Fri, 29 Dec 2023 17:54:52 +0100 Subject: [PATCH 5/6] don't require yardstick for Rakefile to work --- Rakefile | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Rakefile b/Rakefile index 54351ca..423a263 100644 --- a/Rakefile +++ b/Rakefile @@ -12,14 +12,20 @@ RuboCop::RakeTask.new require 'yard' YARD::Rake::YardocTask.new -require 'yardstick/rake/measurement' -Yardstick::Rake::Measurement.new do |measurement| - measurement.output = 'measurement/report.txt' -end +task default: [:spec, :rubocop] -require 'yardstick/rake/verify' -Yardstick::Rake::Verify.new do |verify| - verify.threshold = 67.1 -end +begin + require 'yardstick/rake/measurement' + Yardstick::Rake::Measurement.new do |measurement| + measurement.output = 'measurement/report.txt' + end -task default: [:spec, :rubocop, :verify_measurements] + require 'yardstick/rake/verify' + Yardstick::Rake::Verify.new do |verify| + verify.threshold = 67.1 + end + + Rake::Task[:default].enhance(:verify_measurements) +rescue LoadError + # yardstick not present +end From 80e0d5679cab964571a531c789aeb3f532ce1083 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 29 Dec 2023 16:27:52 +0100 Subject: [PATCH 6/6] Provide an easy way to run acceptance test via rake rspec When either ZABBIX_RUN_ACCEPTANCE or ZABBIX_HOST_URL is set as an environment variable, it's considered that the user opts in to acceptance tests. The acceptance tests previously didn't have the _spec suffix, so they weren't picked up by the file filter. The acceptance tests are dangerous on a production system, so they are now flagged with their own type. Flagging also makes it possible to include specific contexts just for acceptance tests. --- .github/workflows/main.yml | 4 +++- spec/{action.rb => acceptance/action_spec.rb} | 0 .../application_spec.rb} | 0 spec/{basic_func.rb => acceptance/basic_func_spec.rb} | 0 .../configuration_spec.rb} | 0 spec/{drule.rb => acceptance/drule_spec.rb} | 0 spec/{event.rb => acceptance/event_spec.rb} | 0 spec/{graph.rb => acceptance/graph_spec.rb} | 0 spec/{host.rb => acceptance/host_spec.rb} | 0 spec/{hostgroup.rb => acceptance/hostgroup_spec.rb} | 0 spec/{httptest.rb => acceptance/httptest_spec.rb} | 0 spec/{item.rb => acceptance/item_spec.rb} | 0 .../maintenance_spec.rb} | 0 spec/{mediatype.rb => acceptance/mediatype_spec.rb} | 0 spec/{problem.rb => acceptance/problem_spec.rb} | 0 spec/{query.rb => acceptance/query_spec.rb} | 0 spec/{screen.rb => acceptance/screen_spec.rb} | 0 spec/{script.rb => acceptance/script_spec.rb} | 0 spec/{server.rb => acceptance/server_spec.rb} | 0 spec/{template.rb => acceptance/template_spec.rb} | 0 spec/{trigger.rb => acceptance/trigger_spec.rb} | 0 spec/{user.rb => acceptance/user_spec.rb} | 0 spec/{usergroup.rb => acceptance/usergroup_spec.rb} | 0 spec/{usermacro.rb => acceptance/usermacro_spec.rb} | 0 spec/{valuemap.rb => acceptance/valuemap_spec.rb} | 0 spec/spec_helper.rb | 11 +++++++++++ 26 files changed, 14 insertions(+), 1 deletion(-) rename spec/{action.rb => acceptance/action_spec.rb} (100%) rename spec/{application.rb => acceptance/application_spec.rb} (100%) rename spec/{basic_func.rb => acceptance/basic_func_spec.rb} (100%) rename spec/{configuration.rb => acceptance/configuration_spec.rb} (100%) rename spec/{drule.rb => acceptance/drule_spec.rb} (100%) rename spec/{event.rb => acceptance/event_spec.rb} (100%) rename spec/{graph.rb => acceptance/graph_spec.rb} (100%) rename spec/{host.rb => acceptance/host_spec.rb} (100%) rename spec/{hostgroup.rb => acceptance/hostgroup_spec.rb} (100%) rename spec/{httptest.rb => acceptance/httptest_spec.rb} (100%) rename spec/{item.rb => acceptance/item_spec.rb} (100%) rename spec/{maintenance.rb => acceptance/maintenance_spec.rb} (100%) rename spec/{mediatype.rb => acceptance/mediatype_spec.rb} (100%) rename spec/{problem.rb => acceptance/problem_spec.rb} (100%) rename spec/{query.rb => acceptance/query_spec.rb} (100%) rename spec/{screen.rb => acceptance/screen_spec.rb} (100%) rename spec/{script.rb => acceptance/script_spec.rb} (100%) rename spec/{server.rb => acceptance/server_spec.rb} (100%) rename spec/{template.rb => acceptance/template_spec.rb} (100%) rename spec/{trigger.rb => acceptance/trigger_spec.rb} (100%) rename spec/{user.rb => acceptance/user_spec.rb} (100%) rename spec/{usergroup.rb => acceptance/usergroup_spec.rb} (100%) rename spec/{usermacro.rb => acceptance/usermacro_spec.rb} (100%) rename spec/{valuemap.rb => acceptance/valuemap_spec.rb} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8994d0e..3869693 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,4 +63,6 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true - name: Run tests - run: bundle exec rspec ./spec/* + run: bundle exec rake spec + env: + ZABBIX_RUN_ACCEPTANCE: true diff --git a/spec/action.rb b/spec/acceptance/action_spec.rb similarity index 100% rename from spec/action.rb rename to spec/acceptance/action_spec.rb diff --git a/spec/application.rb b/spec/acceptance/application_spec.rb similarity index 100% rename from spec/application.rb rename to spec/acceptance/application_spec.rb diff --git a/spec/basic_func.rb b/spec/acceptance/basic_func_spec.rb similarity index 100% rename from spec/basic_func.rb rename to spec/acceptance/basic_func_spec.rb diff --git a/spec/configuration.rb b/spec/acceptance/configuration_spec.rb similarity index 100% rename from spec/configuration.rb rename to spec/acceptance/configuration_spec.rb diff --git a/spec/drule.rb b/spec/acceptance/drule_spec.rb similarity index 100% rename from spec/drule.rb rename to spec/acceptance/drule_spec.rb diff --git a/spec/event.rb b/spec/acceptance/event_spec.rb similarity index 100% rename from spec/event.rb rename to spec/acceptance/event_spec.rb diff --git a/spec/graph.rb b/spec/acceptance/graph_spec.rb similarity index 100% rename from spec/graph.rb rename to spec/acceptance/graph_spec.rb diff --git a/spec/host.rb b/spec/acceptance/host_spec.rb similarity index 100% rename from spec/host.rb rename to spec/acceptance/host_spec.rb diff --git a/spec/hostgroup.rb b/spec/acceptance/hostgroup_spec.rb similarity index 100% rename from spec/hostgroup.rb rename to spec/acceptance/hostgroup_spec.rb diff --git a/spec/httptest.rb b/spec/acceptance/httptest_spec.rb similarity index 100% rename from spec/httptest.rb rename to spec/acceptance/httptest_spec.rb diff --git a/spec/item.rb b/spec/acceptance/item_spec.rb similarity index 100% rename from spec/item.rb rename to spec/acceptance/item_spec.rb diff --git a/spec/maintenance.rb b/spec/acceptance/maintenance_spec.rb similarity index 100% rename from spec/maintenance.rb rename to spec/acceptance/maintenance_spec.rb diff --git a/spec/mediatype.rb b/spec/acceptance/mediatype_spec.rb similarity index 100% rename from spec/mediatype.rb rename to spec/acceptance/mediatype_spec.rb diff --git a/spec/problem.rb b/spec/acceptance/problem_spec.rb similarity index 100% rename from spec/problem.rb rename to spec/acceptance/problem_spec.rb diff --git a/spec/query.rb b/spec/acceptance/query_spec.rb similarity index 100% rename from spec/query.rb rename to spec/acceptance/query_spec.rb diff --git a/spec/screen.rb b/spec/acceptance/screen_spec.rb similarity index 100% rename from spec/screen.rb rename to spec/acceptance/screen_spec.rb diff --git a/spec/script.rb b/spec/acceptance/script_spec.rb similarity index 100% rename from spec/script.rb rename to spec/acceptance/script_spec.rb diff --git a/spec/server.rb b/spec/acceptance/server_spec.rb similarity index 100% rename from spec/server.rb rename to spec/acceptance/server_spec.rb diff --git a/spec/template.rb b/spec/acceptance/template_spec.rb similarity index 100% rename from spec/template.rb rename to spec/acceptance/template_spec.rb diff --git a/spec/trigger.rb b/spec/acceptance/trigger_spec.rb similarity index 100% rename from spec/trigger.rb rename to spec/acceptance/trigger_spec.rb diff --git a/spec/user.rb b/spec/acceptance/user_spec.rb similarity index 100% rename from spec/user.rb rename to spec/acceptance/user_spec.rb diff --git a/spec/usergroup.rb b/spec/acceptance/usergroup_spec.rb similarity index 100% rename from spec/usergroup.rb rename to spec/acceptance/usergroup_spec.rb diff --git a/spec/usermacro.rb b/spec/acceptance/usermacro_spec.rb similarity index 100% rename from spec/usermacro.rb rename to spec/acceptance/usermacro_spec.rb diff --git a/spec/valuemap.rb b/spec/acceptance/valuemap_spec.rb similarity index 100% rename from spec/valuemap.rb rename to spec/acceptance/valuemap_spec.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8bcd1c0..91fd51e 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,16 @@ require 'zabbixapi' +RSpec.configure do |config| + config.define_derived_metadata(file_path: %r{/spec/acceptance/}) do |metadata| + metadata[:type] = :acceptance + end + + # Don't run acceptance tests unless a host is provided + unless (ENV.key?('ZABBIX_HOST_URL') || ENV.key?('ZABBIX_RUN_ACCEPTANCE')) + config.filter_run_excluding type: :acceptance + end +end + def zbx # settings @api_url = ENV['ZABBIX_HOST_URL'] || 'http://localhost:8080/api_jsonrpc.php'