From 8f1ef580410398cd5d5a3670f9909f27b0234719 Mon Sep 17 00:00:00 2001 From: OpsLevel Coding Agent Date: Thu, 15 Jan 2026 19:50:47 +0000 Subject: [PATCH] Changes made by OpsLevel coding agent. --- .github/workflows/test.yml | 29 ++++++++ README.md | 19 ++++++ Rakefile | 9 +++ test/pager_duty_connection_test.rb | 102 +++++++++++++++++++++++++++++ test/test_helper.rb | 3 + 5 files changed, 162 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 test/pager_duty_connection_test.rb create mode 100644 test/test_helper.rb diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..41c56d5 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,29 @@ +name: Tests + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: ['2.7', '3.0', '3.1', '3.2'] + + steps: + - uses: actions/checkout@v3 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + + - name: Install dependencies + run: bundle install + + - name: Run tests + run: bundle exec rake test diff --git a/README.md b/README.md index 0d8114f..a6cd8ad 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # PagerDuty::Connection +[![Tests](https://github.com/technicalpickles/pager_duty-connection/workflows/Tests/badge.svg)](https://github.com/technicalpickles/pager_duty-connection/actions?query=workflow%3ATests) + PagerDuty::Connection is a Ruby wrapper for the [PagerDuty REST API](http://developer.pagerduty.com/documentation/rest) It has a few design goals: @@ -141,6 +143,23 @@ That would suggest a constant like Pagerduty::Connection, where the company is c It's an homage to [faraday](https://github.com/lostisland/faraday), which this library uses. +## Testing + +This project uses Minitest for testing. To run the test suite: + +```bash +bundle install +bundle exec rake test +``` + +The test suite includes basic smoke tests that verify: +- Module and class definitions are loaded correctly +- Connection initialization works with various parameters +- All public API methods are available +- Error classes are properly defined + +When contributing, please ensure your changes include appropriate tests. + ## Contributing 1. Fork it diff --git a/Rakefile b/Rakefile index 2995527..3d52175 100644 --- a/Rakefile +++ b/Rakefile @@ -1 +1,10 @@ require "bundler/gem_tasks" +require "rake/testtask" + +Rake::TestTask.new(:test) do |t| + t.libs << "test" + t.libs << "lib" + t.test_files = FileList["test/**/*_test.rb"] +end + +task default: :test diff --git a/test/pager_duty_connection_test.rb b/test/pager_duty_connection_test.rb new file mode 100644 index 0000000..9492906 --- /dev/null +++ b/test/pager_duty_connection_test.rb @@ -0,0 +1,102 @@ +require_relative "test_helper" + +class PagerDutyConnectionTest < Minitest::Test + def test_module_exists + assert defined?(PagerDuty), "PagerDuty module should be defined" + end + + def test_connection_class_exists + assert defined?(PagerDuty::Connection), "PagerDuty::Connection class should be defined" + end + + def test_version_constant_exists + assert defined?(PagerDuty::Connection::VERSION), "VERSION constant should be defined" + end + + def test_version_format + assert_match(/\d+\.\d+\.\d+/, PagerDuty::Connection::VERSION, "VERSION should follow semantic versioning") + end + + def test_api_version_constant + assert_equal 2, PagerDuty::Connection::API_VERSION, "API_VERSION should be 2" + end + + def test_api_prefix_constant + assert_equal "https://api.pagerduty.com/", PagerDuty::Connection::API_PREFIX, "API_PREFIX should be correct" + end + + def test_connection_accepts_token + # Connection initialization should work with a token + # This is a smoke test to ensure initialization doesn't raise unexpected errors + connection = PagerDuty::Connection.new("test_token_123") + assert_instance_of PagerDuty::Connection, connection + end + + def test_connection_has_connection_attribute + connection = PagerDuty::Connection.new("test_token_123") + assert_respond_to connection, :connection + end + + def test_connection_responds_to_get + connection = PagerDuty::Connection.new("test_token_123") + assert_respond_to connection, :get + end + + def test_connection_responds_to_post + connection = PagerDuty::Connection.new("test_token_123") + assert_respond_to connection, :post + end + + def test_connection_responds_to_put + connection = PagerDuty::Connection.new("test_token_123") + assert_respond_to connection, :put + end + + def test_connection_responds_to_delete + connection = PagerDuty::Connection.new("test_token_123") + assert_respond_to connection, :delete + end + + def test_file_not_found_error_exists + assert defined?(PagerDuty::Connection::FileNotFoundError) + assert PagerDuty::Connection::FileNotFoundError < RuntimeError + end + + def test_api_error_exists + assert defined?(PagerDuty::Connection::ApiError) + assert PagerDuty::Connection::ApiError < RuntimeError + end + + def test_rate_limit_error_exists + assert defined?(PagerDuty::Connection::RateLimitError) + assert PagerDuty::Connection::RateLimitError < RuntimeError + end + + def test_unauthorized_error_exists + assert defined?(PagerDuty::Connection::UnauthorizedError) + assert PagerDuty::Connection::UnauthorizedError < RuntimeError + end + + def test_forbidden_error_exists + assert defined?(PagerDuty::Connection::ForbiddenError) + assert PagerDuty::Connection::ForbiddenError < RuntimeError + end + + def test_connection_with_bearer_token + connection = PagerDuty::Connection.new("bearer_token_123", token_type: :Bearer) + assert_instance_of PagerDuty::Connection, connection + end + + def test_connection_with_custom_url + custom_url = "https://custom.pagerduty.com/" + connection = PagerDuty::Connection.new("test_token", url: custom_url) + assert_instance_of PagerDuty::Connection, connection + end + + def test_connection_with_invalid_token_type + error = assert_raises(ArgumentError) do + PagerDuty::Connection.new("test_token", token_type: :InvalidType) + end + assert_match(/invalid token_type/, error.message) + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..2b0d8e3 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,3 @@ +require "minitest/autorun" +require "minitest/pride" +require_relative "../lib/pager_duty-connection"