Skip to content

Commit d9fcace

Browse files
committed
Fix version comparison
1 parent 85496eb commit d9fcace

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

app/services/namespaces/projects/assign_runtimes_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def execute
3232
)
3333
end
3434

35-
UpdateRuntimeCompatibilityJob.perform_later(namespace_project_id: namespace_project.id)
35+
UpdateRuntimeCompatibilityJob.perform_later({ namespace_project_id: namespace_project.id })
3636

3737
AuditService.audit(
3838
:project_runtimes_assigned,

app/services/runtimes/check_runtime_compatibility_service.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def execute
1414

1515
if primary_runtime.nil?
1616
return ServiceResponse.error(message: 'No primary runtime given',
17-
payload: :missing_primary_runtime)
17+
error_code: :missing_primary_runtime)
1818
end
1919

2020
{ DataType => :identifier, FlowType => :identifier,
@@ -31,29 +31,31 @@ def check_versions(model, identifier_field = :identifier)
3131

3232
if to_check_types.size < primary_types.size
3333
return ServiceResponse.error(message: "#{model} amount dont match",
34-
payload: :missing_definition)
34+
error_code: :missing_definition)
3535
end
3636

3737
primary_types.each do |curr_type|
3838
to_check = model.find_by(runtime: runtime, identifier_field => curr_type.send(identifier_field))
3939
if to_check.nil?
4040
return ServiceResponse.error(message: "#{model} is not present in new runtime",
41-
payload: :missing_definition)
41+
error_code: :missing_definition)
4242
end
4343

4444
result = compare_version(curr_type.parsed_version, to_check.parsed_version)
4545

4646
unless result
4747
return ServiceResponse.error(message: "#{model} is outdated",
48-
payload: :outdated_definition)
48+
error_code: :outdated_definition)
4949
end
5050
end
5151
ServiceResponse.success
5252
end
5353

54+
# true: compatible
55+
# false: not compatible
5456
def compare_version(primary_version, to_check_version)
5557
return false if primary_version.segments[0] != to_check_version.segments[0]
56-
return false if primary_version.segments[1] < to_check_version.segments[1]
58+
return false if primary_version.segments[1] > to_check_version.segments[1]
5759

5860
true
5961
end

spec/jobs/update_runtime_compatibility_job_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
assignment2 = create(:namespace_project_runtime_assignment, compatible: false)
1111

1212
success_res = ServiceResponse.success
13-
err_response = ServiceResponse.error
13+
err_response = ServiceResponse.error(error_code: :outdated_definition, message: 'Runtime is outdated')
1414

1515
service1 = instance_double(Runtimes::CheckRuntimeCompatibilityService, execute: success_res)
1616
service2 = instance_double(Runtimes::CheckRuntimeCompatibilityService, execute: err_response)

spec/services/runtimes/check_runtime_compatibility_service_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
it 'returns an error with :missing_primary_runtime payload' do
1818
expect(service_response).to be_error
19-
expect(service_response.payload).to eq(:missing_primary_runtime)
19+
expect(service_response.payload[:error_code]).to eq(:missing_primary_runtime)
2020
end
2121
end
2222

@@ -27,29 +27,29 @@
2727

2828
it 'returns missing_datatypes error' do
2929
expect(service_response.error?).to be true
30-
expect(service_response.payload).to eq(:missing_definition)
30+
expect(service_response.payload[:error_code]).to eq(:missing_definition)
3131
end
3232
end
3333

34-
context 'when a data type version is newer on runtime than primary (outdated primary)' do
34+
context 'when secondary runtime has outdated definitions' do
3535
before do
36-
create(:data_type, runtime: primary_runtime, identifier: 'dt1', version: '1.1.0')
36+
create(:data_type, runtime: primary_runtime, identifier: 'dt1', version: '1.3.0')
3737
create(:data_type, runtime: runtime, identifier: 'dt1', version: '1.2.0')
3838
end
3939

4040
it 'returns outdated_data_type error' do
4141
expect(service_response.error?).to be true
42-
expect(service_response.payload).to eq(:outdated_definition)
42+
expect(service_response.payload[:error_code]).to eq(:outdated_definition)
4343
end
4444
end
4545

4646
context 'when all models are compatible' do
4747
before do
48-
create(:data_type, runtime: primary_runtime, identifier: 'dt1', version: '1.2.0')
49-
create(:data_type, runtime: runtime, identifier: 'dt1', version: '1.1.0')
48+
create(:data_type, runtime: primary_runtime, identifier: 'dt1', version: '1.3.0')
49+
create(:data_type, runtime: runtime, identifier: 'dt1', version: '1.3.0')
5050
create(:flow_type, runtime: primary_runtime, identifier: 'ft1', version: '2.1.0')
51-
create(:flow_type, runtime: runtime, identifier: 'ft1', version: '2.0.0')
52-
create(:runtime_function_definition, runtime_name: 'rfd1', runtime: primary_runtime, version: '3.2.0')
51+
create(:flow_type, runtime: runtime, identifier: 'ft1', version: '2.2.0')
52+
create(:runtime_function_definition, runtime_name: 'rfd1', runtime: primary_runtime, version: '3.0.0')
5353
create(:runtime_function_definition, runtime_name: 'rfd1', runtime: runtime, version: '3.1.0')
5454
end
5555

0 commit comments

Comments
 (0)