From aa2e095ee8def306b6344b162c026193838b3e95 Mon Sep 17 00:00:00 2001 From: Brian Watson Date: Mon, 7 Feb 2022 13:45:37 -0700 Subject: [PATCH] Handle long crystalball spec key name entries in yaml dump flag=none Test-plan: - build map in jenkins - push map to s3 manually - reference map in test PS Change-Id: I78c0c57f970256f84120fe3c336e882d6f3d41e2 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/284590 Tested-by: Service Cloud Jenkins Reviewed-by: James Butters QA-Review: James Butters Product-Review: James Butters --- spec/support/crystalball.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/support/crystalball.rb b/spec/support/crystalball.rb index ad6eb06938c1a..953dbda896a80 100644 --- a/spec/support/crystalball.rb +++ b/spec/support/crystalball.rb @@ -198,6 +198,22 @@ def includes_root?(prediction_list) prediction_list.include?(ENV["CRYSTALBALL_TEST_SUITE_ROOT"]) end end + + class MapStorage + # YAML persistence adapter for execution map storage + class YAMLStorage + def dump(data) + path.dirname.mkpath + # Any keys longer than 128 chars will have a yaml output starting with "? \n:" instead of ":\n", which crystalball doesn't like + data_dump = if %i[type commit timestamp version].all? { |header| data.key? header } + YAML.dump(data) + else + YAML.dump(data).gsub("? ", "").gsub("\n:", ":\n").gsub("\n -", "\n-").gsub("\n -", "\n-") + end + path.open("a") { |f| f.write data_dump } + end + end + end end require "crystalball/rspec/runner/configuration"