Skip to content

Commit 6a347af

Browse files
committed
feat(test): add helper method for deprecated tests
1 parent fe931ca commit 6a347af

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

spec/spec_helper.rb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,43 @@ def typesense_healthy?(host = 'localhost', port = 8108)
3434
false
3535
end
3636

37+
def typesense_version
38+
begin
39+
WebMock.allow_net_connect!
40+
conn = Faraday.new('http://localhost:8108')
41+
response = conn.get('/debug') do |req|
42+
req.headers['X-TYPESENSE-API-KEY'] = 'xyz'
43+
end
44+
45+
if response.status == 200 && !response.body.empty?
46+
debug_info = JSON.parse(response.body)
47+
version = debug_info['version']
48+
version
49+
else
50+
nil
51+
end
52+
rescue StandardError => e
53+
nil
54+
ensure
55+
WebMock.disable_net_connect!(allow_localhost: true)
56+
end
57+
end
58+
59+
def typesense_v30_or_above?
60+
version = typesense_version
61+
return false unless version
62+
63+
if version == 'nightly'
64+
return true
65+
end
66+
67+
if version.match(/^v(\d+)/)
68+
major_version = $1.to_i
69+
return major_version >= 30
70+
end
71+
false
72+
end
73+
3774
def ensure_typesense_running
3875
if typesense_healthy?
3976
puts '✅ Typesense is already running and healthy, ready for use in integration tests'
@@ -96,7 +133,6 @@ def stop_typesense_if_started
96133

97134
config.before(:suite) do
98135
ensure_typesense_running
99-
WebMock.disable_net_connect!
100136
end
101137

102138
config.after(:suite) do

0 commit comments

Comments
 (0)