diff options
Diffstat (limited to 'spec/lib/api/entities')
-rw-r--r-- | spec/lib/api/entities/bulk_imports/entity_failure_spec.rb | 19 | ||||
-rw-r--r-- | spec/lib/api/entities/ml/mlflow/run_spec.rb | 50 |
2 files changed, 63 insertions, 6 deletions
diff --git a/spec/lib/api/entities/bulk_imports/entity_failure_spec.rb b/spec/lib/api/entities/bulk_imports/entity_failure_spec.rb index adc8fdcdd9c..0132102b117 100644 --- a/spec/lib/api/entities/bulk_imports/entity_failure_spec.rb +++ b/spec/lib/api/entities/bulk_imports/entity_failure_spec.rb @@ -9,11 +9,26 @@ RSpec.describe API::Entities::BulkImports::EntityFailure do it 'has the correct attributes' do expect(subject).to include( - :pipeline_class, - :pipeline_step, + :relation, + :step, :exception_class, + :exception_message, :correlation_id_value, :created_at ) end + + describe 'exception message' do + it 'truncates exception message to 72 characters' do + failure.update!(exception_message: 'a' * 100) + + expect(subject[:exception_message].length).to eq(72) + end + + it 'removes paths from the message' do + failure.update!(exception_message: 'Test /foo/bar') + + expect(subject[:exception_message]).to eq('Test [FILTERED]') + end + end end diff --git a/spec/lib/api/entities/ml/mlflow/run_spec.rb b/spec/lib/api/entities/ml/mlflow/run_spec.rb index 84234f474f5..b8d38093681 100644 --- a/spec/lib/api/entities/ml/mlflow/run_spec.rb +++ b/spec/lib/api/entities/ml/mlflow/run_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe API::Entities::Ml::Mlflow::Run do - let_it_be(:candidate) { create(:ml_candidates) } + let_it_be(:candidate) { create(:ml_candidates, :with_metrics_and_params) } subject { described_class.new(candidate).as_json } @@ -12,10 +12,52 @@ RSpec.describe API::Entities::Ml::Mlflow::Run do end it 'has the id' do - expect(subject[:run][:info][:run_id]).to eq(candidate.iid.to_s) + expect(subject.dig(:run, :info, :run_id)).to eq(candidate.iid.to_s) end - it 'data is empty' do - expect(subject[:run][:data]).to be_empty + it 'presents the metrics' do + expect(subject.dig(:run, :data, :metrics).size).to eq(candidate.metrics.size) + end + + it 'presents metrics correctly' do + presented_metric = subject.dig(:run, :data, :metrics)[0] + metric = candidate.metrics[0] + + expect(presented_metric[:key]).to eq(metric.name) + expect(presented_metric[:value]).to eq(metric.value) + expect(presented_metric[:timestamp]).to eq(metric.tracked_at) + expect(presented_metric[:step]).to eq(metric.step) + end + + it 'presents the params' do + expect(subject.dig(:run, :data, :params).size).to eq(candidate.params.size) + end + + it 'presents params correctly' do + presented_param = subject.dig(:run, :data, :params)[0] + param = candidate.params[0] + + expect(presented_param[:key]).to eq(param.name) + expect(presented_param[:value]).to eq(param.value) + end + + context 'when candidate has no metrics' do + before do + allow(candidate).to receive(:metrics).and_return([]) + end + + it 'returns empty data' do + expect(subject.dig(:run, :data, :metrics)).to be_empty + end + end + + context 'when candidate has no params' do + before do + allow(candidate).to receive(:params).and_return([]) + end + + it 'data is empty' do + expect(subject.dig(:run, :data, :params)).to be_empty + end end end |