Skip to content

Commit 1c46237

Browse files
authored
gha: run ruby e2e tests in github (#2558)
1 parent e0a3fe2 commit 1c46237

5 files changed

Lines changed: 109 additions & 27 deletions

File tree

.github/workflows/ruby-lint.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: Ruby Lint
1+
name: Ruby Lint and Tests
22

33
on:
44
workflow_call:
55

66
jobs:
77
ruby:
8-
name: Ruby Lint
8+
name: Ruby Lint and Tests and Tests
99
runs-on: ubuntu-24.04
1010

1111
strategy:
@@ -15,22 +15,23 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v7
1717

18+
- name: Pull svix server image (and dependencies)
19+
run: docker compose pull
20+
working-directory: ./client-integration-tests
21+
1822
- name: Setup Ruby
1923
uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0
2024
with:
2125
ruby-version: ${{ matrix.ruby-version }}
2226

2327
- name: Install dependencies
24-
run: |
25-
cd ruby
26-
bundler install
28+
working-directory: ruby
29+
run: bundle install
2730

2831
- name: Build
29-
run: |
30-
cd ruby
31-
bundler exec rake build
32+
working-directory: ruby
33+
run: bundle exec rake build
3234

3335
- name: Test
34-
run: |
35-
cd ruby
36-
bundler exec rspec spec
36+
working-directory: ruby
37+
run: bundle exec rspec spec

ruby/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ source "https://rubygems.org"
33
gem 'base64'
44
gem 'logger'
55
gem 'ostruct'
6+
gem "irb"
67

78
gemspec

ruby/Gemfile.lock

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,33 @@ GEM
1616
bigdecimal
1717
rexml
1818
diff-lcs (1.6.2)
19+
erb (6.0.7)
1920
hashdiff (1.2.1)
21+
io-console (0.9.2)
22+
irb (1.18.0)
23+
pp (>= 0.6.0)
24+
prism (>= 1.3.0)
25+
rdoc (>= 4.0.0)
26+
reline (>= 0.4.2)
2027
logger (1.7.0)
2128
ostruct (0.6.3)
29+
pp (0.6.4)
30+
prettyprint
31+
prettyprint (0.2.0)
32+
prism (1.9.0)
2233
public_suffix (7.0.5)
2334
rake (13.4.1)
35+
rbs (4.1.3)
36+
logger
37+
prism (>= 1.6.0)
38+
tsort
39+
rdoc (8.0.0)
40+
erb
41+
prism (>= 1.6.0)
42+
rbs (>= 4.0.0)
43+
tsort
44+
reline (0.7.0)
45+
io-console (~> 0.5)
2446
rexml (3.4.4)
2547
rspec (3.13.2)
2648
rspec-core (~> 3.13.0)
@@ -35,6 +57,8 @@ GEM
3557
diff-lcs (>= 1.2.0, < 2.0)
3658
rspec-support (~> 3.13.0)
3759
rspec-support (3.13.7)
60+
subprocess (1.5.7)
61+
tsort (0.2.0)
3862
webmock (3.26.2)
3963
addressable (>= 2.8.0)
4064
crack (>= 0.3.2)
@@ -45,10 +69,12 @@ PLATFORMS
4569

4670
DEPENDENCIES
4771
base64
72+
irb (~> 1.18)
4873
logger
4974
ostruct
5075
rake (~> 13.0)
5176
rspec (~> 3.2)
77+
subprocess (~> 1.5)
5278
svix!
5379
webmock (~> 3.25)
5480

ruby/spec/kitchen_sink_spec.rb

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,99 @@
11
# frozen_string_literal: true
22

33
require_relative "../lib/svix"
4+
require 'subprocess'
45

5-
token = ENV["SVIX_TOKEN"]
6-
server_url = ENV["SVIX_SERVER_URL"]
7-
test_client = nil
6+
SVIX_ORG_ID = "org_svix_ruby_tests"
7+
DOCKER_COMPOSE_DIR = File.join(File.dirname(__FILE__), '..', '..', 'client-integration-tests')
88

9-
if token.nil? || server_url.nil?
10-
warn("Unable to instantiate test client without both `SVIX_TOKEN` and `SVIX_SERVER_URL`")
11-
else
12-
opts = Svix::SvixOptions.new(false, server_url)
13-
test_client = Svix::Client.new(token, opts)
9+
def docker_compose(*args)
10+
args = ['docker', 'compose', *args]
11+
process = Subprocess::Process.new(args, {cwd: DOCKER_COMPOSE_DIR, stdout: Subprocess::PIPE, stderr: Subprocess::PIPE})
12+
stdout, stderr = process.communicate
13+
status = process.wait
14+
if !status.success?
15+
$stderr.puts "#{args} failed with status #{status}"
16+
$stderr.puts stderr
17+
raise "Called process failed"
18+
end
19+
stdout
20+
end
21+
22+
def docker_generate_token
23+
raw_output = docker_compose('exec', '-T', 'backend', 'svix-server', 'jwt', 'generate', SVIX_ORG_ID)
24+
if (md = /Token \(Bearer\): (.*)/.match(raw_output))
25+
md[1]
26+
else
27+
raise "Failed to generate JWT: #{raw_output}"
28+
end
29+
end
30+
31+
def docker_compose_port_for(service_name, container_port)
32+
docker_compose('ps', '--format=json').split("\n").filter_map do |line|
33+
json = JSON.parse(line)
34+
if json["Service"] == service_name
35+
if port_row = json["Publishers"].find { |row| row["TargetPort"] == container_port }
36+
port_row["PublishedPort"]
37+
end
38+
end
39+
end.first
1440
end
1541

42+
1643
RSpec.describe Svix::Client do
17-
describe "Endpoint CRUD", {if: !test_client.nil?} do
44+
before :all do
45+
if ENV["SVIX_TOKEN"].nil?
46+
docker_compose "up", "-d", "--quiet-pull"
47+
$token = docker_generate_token
48+
$server_url = "http://localhost:#{docker_compose_port_for("backend", 8071)}"
49+
else
50+
$token = ENV["SVIX_TOKEN"]
51+
$server_url = ENV["SVIX_SERVER_URL"]
52+
end
53+
end
54+
55+
after :all do
56+
if ENV["SVIX_TOKEN"].nil?
57+
docker_compose("down", "-v")
58+
end
59+
end
60+
61+
before :each do
62+
if ENV["SVIX_TOKEN"].nil?
63+
docker_compose('exec', '-T', 'backend', 'svix-server', 'wipe', '--yes-i-know-what-im-doing', SVIX_ORG_ID)
64+
end
65+
66+
opts = Svix::SvixOptions.new(false, $server_url)
67+
@test_client = Svix::Client.new($token, opts)
68+
end
69+
70+
describe "Endpoint CRUD" do
1871
it "seems to work okay" do
19-
app = test_client.application.create(Svix::ApplicationIn.new(name: "App"))
72+
app = @test_client.application.create(Svix::ApplicationIn.new(name: "App"))
2073

2174
begin
22-
test_client.event_type.create(Svix::EventTypeIn.new(name: "event.started", description: "Something started"))
75+
@test_client.event_type.create(Svix::EventTypeIn.new(name: "event.started", description: "Something started"))
2376
rescue Svix::ApiError => err
2477
# Conflicts are expected from test run to test run, but other statuses are not.
2578
expect(err.code).to(eq(409))
2679
end
2780

2881
begin
29-
test_client.event_type.create(Svix::EventTypeIn.new(name: "event.ended", description: "Something ended"))
82+
@test_client.event_type.create(Svix::EventTypeIn.new(name: "event.ended", description: "Something ended"))
3083
rescue Svix::ApiError => err
3184
# Conflicts are expected from test run to test run, but other statuses are not.
3285
expect(err.code).to(eq(409))
3386
end
3487

35-
ep = test_client.endpoint.create(
88+
ep = @test_client.endpoint.create(
3689
app.id,
3790
Svix::EndpointIn.new(url: "https://example.svix.com/", channels: %w[ch0 ch1])
3891
)
3992

4093
expect(ep.channels.to_set).to(eq(%w[ch0 ch1].to_set))
4194
expect(ep.event_types).to(be_nil)
4295

43-
ep_patched = test_client.endpoint.patch(
96+
ep_patched = @test_client.endpoint.patch(
4497
app.id,
4598
ep.id,
4699
Svix::EndpointPatch.new(event_types: %w[event.started event.ended])
@@ -50,7 +103,7 @@
50103
expect(ep_patched.event_types.to_set).to(eq(%w[event.started event.ended].to_set))
51104

52105
# If the serialization is handling empty response bodies, this should not throw an exception
53-
test_client.endpoint.delete(app.id, ep.id)
106+
@test_client.endpoint.delete(app.id, ep.id)
54107
end
55108
end
56109
end

ruby/svix.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ Gem::Specification.new do |spec|
4848

4949
spec.add_development_dependency "rake", "~> 13.0"
5050
spec.add_development_dependency "rspec", "~> 3.2"
51-
spec.add_development_dependency 'webmock', '~> 3.25'
51+
spec.add_development_dependency "webmock", "~> 3.25"
52+
spec.add_development_dependency "subprocess", "~> 1.5"
5253
end

0 commit comments

Comments
 (0)