From 238443852abc8acb4575e48a64985bcb8f8c49a5 Mon Sep 17 00:00:00 2001 From: JoannaaKL Date: Thu, 1 Jun 2023 09:53:37 +0000 Subject: [PATCH] wip --- .../DTObjectTemplating/TemplateContextL0.cs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/Test/L0/Sdk/DTObjectTemplating/TemplateContextL0.cs diff --git a/src/Test/L0/Sdk/DTObjectTemplating/TemplateContextL0.cs b/src/Test/L0/Sdk/DTObjectTemplating/TemplateContextL0.cs new file mode 100644 index 000000000..2a4815305 --- /dev/null +++ b/src/Test/L0/Sdk/DTObjectTemplating/TemplateContextL0.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using GitHub.DistributedTask.ObjectTemplating.Tokens; +using Xunit; + +namespace GitHub.DistributedTask.ObjectTemplating.Tests +{ + public sealed class TemplateContextL0 + { + [Fact] + [Trait("Level", "L0")] + [Trait("Category", "Common")] + public void VerifyError() + { + TemplateContext context = buildContext(); + TemplateToken value = new StringToken(1, 1, 1, "some-token"); + System.Exception ex = new System.Exception(); + + List expectedErrors = new(); + expectedErrors.Add(new TemplateValidationError("(Line: 1, Col: 1): Exception of type 'System.Exception' was thrown.")); + + context.Error(value, ex); + + + Assert.True(expectedErrors.SequenceEqual(toList(context.Errors.GetEnumerator()))); + + + Assert.True(true); + } + + private TemplateContext buildContext() + { + return new TemplateContext + { + // CancellationToken = CancellationToken.None, + Errors = new TemplateValidationErrors(10, int.MaxValue), // Don't truncate error messages otherwise we might not scrub secrets correctly + Memory = new TemplateMemory( + maxDepth: 100, + maxEvents: 1000000, + maxBytes: 10 * 1024 * 1024), + Schema = null, + TraceWriter = new EmptyTraceWriter(), + }; + } + + private List toList(IEnumerator enumerator) + { + List result = new(); + while (enumerator.MoveNext()) + { + TemplateValidationError err = enumerator.Current; + result.Add(err); + } + return result; + } + } +}