Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
102 changes: 102 additions & 0 deletions test/pager_duty_connection_test.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "minitest/autorun"
require "minitest/pride"
require_relative "../lib/pager_duty-connection"
Loading