Skip to content

Commit 5836dbf

Browse files
committed
Run Ruby e2e upload test in CI
1 parent 41c16e4 commit 5836dbf

File tree

6 files changed

+22
-68
lines changed

6 files changed

+22
-68
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,21 @@ jobs:
4343
token: ${{ secrets.CODECOV_TOKEN }}
4444
files: ./coverage/coverage.json
4545
fail_ci_if_error: true
46+
e2e:
47+
needs: ci
48+
if: >
49+
github.event_name != 'pull_request' ||
50+
github.event.pull_request.head.repo.full_name == github.repository
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v3
54+
- uses: ruby/setup-ruby@v1
55+
with:
56+
ruby-version: 3.3
57+
bundler-cache: true
58+
- name: Run end-to-end upload test
59+
env:
60+
RUBY_SDK_E2E: 1
61+
TRANSLOADIT_KEY: ${{ secrets.TRANSLOADIT_KEY }}
62+
TRANSLOADIT_SECRET: ${{ secrets.TRANSLOADIT_SECRET }}
63+
run: bundle exec ruby -Itest test/integration/test_e2e_upload.rb

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ To exercise the optional end-to-end upload against a real Transloadit account, p
521521
RUBY_SDK_E2E=1 ./scripts/test-in-docker.sh bundle exec ruby -Itest test/integration/test_e2e_upload.rb
522522
```
523523

524-
The test uploads `chameleon.jpg`, resizes it, and asserts on the live assembly results. It respects `TRANSLOADIT_HOST` and `TRANSLOADIT_REGION` overrides when present.
524+
The test uploads `chameleon.jpg`, resizes it, and asserts on the live assembly results.
525525

526526
### Releasing on RubyGems
527527

lib/transloadit.rb

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
require "date"
33
require "json"
44
require "openssl"
5-
require "uri"
65
require "cgi"
76

87
#
@@ -31,7 +30,6 @@ class Transloadit
3130
attr_accessor :duration
3231

3332
attr_accessor :max_size
34-
attr_accessor :service
3533

3634
#
3735
# Creates a new instance of the Transloadit API.
@@ -49,7 +47,6 @@ def initialize(options = {})
4947
self.secret = options[:secret]
5048
self.duration = options[:duration] || 5 * 60
5149
self.max_size = options[:max_size]
52-
self.service = _normalize_service(options[:service]) || _service_from_region(options[:region])
5350

5451
_ensure_key_provided
5552
end
@@ -110,7 +107,7 @@ def bill(month = Date.today.month, year = Date.today.year)
110107
month = format "%02d", month
111108
path = "bill/#{year}-#{month}"
112109

113-
Transloadit::Request.new(request_url_for(path), secret).get({auth: to_hash})
110+
Transloadit::Request.new(path, secret).get({auth: to_hash})
114111
end
115112

116113
#
@@ -137,22 +134,6 @@ def to_json
137134
MultiJson.dump(to_hash)
138135
end
139136

140-
#
141-
# Resolves an absolute URL for API requests, honoring custom service overrides.
142-
#
143-
# @param [String] path the request path or URL
144-
# @return [String] the resolved URL or original path if already absolute
145-
#
146-
def request_url_for(path)
147-
return path if service.nil? || service.empty?
148-
149-
uri = URI.parse(path.to_s)
150-
return path if uri.host
151-
152-
base = service.end_with?("/") ? service : "#{service}/"
153-
URI.join(base, path.to_s.sub(%r{\A/}, "")).to_s
154-
end
155-
156137
# @param workspace [String] Workspace slug
157138
# @param template [String] Template slug or template ID
158139
# @param input [String] Input value that is provided as `${fields.input}` in the template
@@ -203,30 +184,6 @@ def signed_smart_cdn_url(
203184

204185
private
205186

206-
#
207-
# Normalizes service URLs, returning nil for blank values.
208-
#
209-
def _normalize_service(value)
210-
return nil if value.nil?
211-
212-
str = value.to_s.strip
213-
return nil if str.empty?
214-
215-
str
216-
end
217-
218-
#
219-
# Builds a service URL from a region hint, if one is provided.
220-
#
221-
def _service_from_region(region)
222-
return nil if region.nil?
223-
224-
str = region.to_s.strip
225-
return nil if str.empty?
226-
227-
"https://api2-#{str}.transloadit.com"
228-
end
229-
230187
#
231188
# Raises an ArgumentError if no {#key} has been assigned.
232189
#

lib/transloadit/api_model.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def _do_request(path, params = nil, method = "get", extra_params = nil)
6868
params = {params: params} if ["post", "put", "delete"].include? method
6969
params.merge!(extra_params) unless extra_params.nil?
7070
end
71-
request_url = transloadit.request_url_for(path)
72-
Transloadit::Request.new(request_url, transloadit.secret).public_send(method, params)
71+
Transloadit::Request.new(path, transloadit.secret).public_send(method, params)
7372
end
7473
end

scripts/test-in-docker.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ fi
7676
PASSTHROUGH_ENV_VARS=(
7777
TRANSLOADIT_KEY
7878
TRANSLOADIT_SECRET
79-
TRANSLOADIT_HOST
80-
TRANSLOADIT_REGION
8179
TRANSLOADIT_TEMPLATE_ID
8280
RUBY_SDK_E2E
8381
)

test/integration/test_e2e_upload.rb

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,12 @@
88
@secret = ENV["TRANSLOADIT_SECRET"]
99
skip "TRANSLOADIT_KEY and TRANSLOADIT_SECRET must be set to run live upload tests" if blank?(@key) || blank?(@secret)
1010

11-
@service = resolve_service
12-
1311
@fixture_path = File.expand_path("../../chameleon.jpg", __dir__)
1412
skip "chameleon.jpg fixture missing; run tests from the repository root" unless File.file?(@fixture_path)
1513
end
1614

1715
it "uploads and processes the chameleon image" do
18-
options = {
19-
key: @key,
20-
secret: @secret
21-
}
22-
options[:service] = @service if @service
23-
24-
transloadit = Transloadit.new(options)
16+
transloadit = Transloadit.new(key: @key, secret: @secret)
2517

2618
resize_step = transloadit.step(
2719
"resize",
@@ -81,16 +73,6 @@ def e2e_enabled?
8173
%w[1 true yes on].include?(flag.to_s.strip.downcase)
8274
end
8375

84-
def resolve_service
85-
host = ENV["TRANSLOADIT_HOST"].to_s.strip
86-
return host unless host.empty?
87-
88-
region = ENV["TRANSLOADIT_REGION"].to_s.strip
89-
return nil if region.empty?
90-
91-
"https://api2-#{region}.transloadit.com"
92-
end
93-
9476
def integer_if_present(value)
9577
return nil if blank?(value)
9678

0 commit comments

Comments
 (0)