From 02a462c0ba8794d7a11863752f2b00509c6cbbda Mon Sep 17 00:00:00 2001 From: Joe Cai Date: Thu, 19 Dec 2024 16:21:55 +1100 Subject: [PATCH] Refactor MarkdownRenderer initialization in tests for clarity and consistency --- .../events/events_controller_e2e_test.go | 13 +- server/events/markdown_renderer_test.go | 112 ++++++++++++++---- 2 files changed, 100 insertions(+), 25 deletions(-) diff --git a/server/controllers/events/events_controller_e2e_test.go b/server/controllers/events/events_controller_e2e_test.go index dcdf347994..1a39273d4d 100644 --- a/server/controllers/events/events_controller_e2e_test.go +++ b/server/controllers/events/events_controller_e2e_test.go @@ -1506,7 +1506,18 @@ func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers pullUpdater := &events.PullUpdater{ HidePrevPlanComments: false, VCSClient: e2eVCSClient, - MarkdownRenderer: events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis", false, opt.userConfig.QuietPolicyChecks), + MarkdownRenderer: events.NewMarkdownRenderer( + false, // gitlabSupportsCommonMark + false, // disableApplyAll + false, // disableApply + false, // disableMarkdownFolding + false, // disableRepoLocking + false, // enableDiffMarkdownFormat + "", // markdownTemplateOverridesDir + "atlantis", // executableName + false, // hideUnchangedPlanComments + opt.userConfig.QuietPolicyChecks, // quietPolicyChecks + ), } autoMerger := &events.AutoMerger{ diff --git a/server/events/markdown_renderer_test.go b/server/events/markdown_renderer_test.go index 139896dde8..2fb90c256b 100644 --- a/server/events/markdown_renderer_test.go +++ b/server/events/markdown_renderer_test.go @@ -60,7 +60,18 @@ func TestRenderErr(t *testing.T) { }, } - r := events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis", false, false) + r := events.NewMarkdownRenderer( + false, // gitlabSupportsCommonMark + false, // disableApplyAll + false, // disableApply + false, // disableMarkdownFolding + false, // disableRepoLocking + false, // enableDiffMarkdownFormat + "", // markdownTemplateOverridesDir + "atlantis", // executableName + false, // hideUnchangedPlanComments + false, // quietPolicyChecks + ) logger := logging.NewNoopLogger(t).WithHistory() logText := "log" logger.Info(logText) @@ -124,7 +135,18 @@ func TestRenderFailure(t *testing.T) { }, } - r := events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis", false, false) + r := events.NewMarkdownRenderer( + false, // gitlabSupportsCommonMark + false, // disableApplyAll + false, // disableApply + false, // disableMarkdownFolding + false, // disableRepoLocking + false, // enableDiffMarkdownFormat + "", // markdownTemplateOverridesDir + "atlantis", // executableName + false, // hideUnchangedPlanComments + false, // quietPolicyChecks + ) logger := logging.NewNoopLogger(t).WithHistory() logText := "log" logger.Info(logText) @@ -163,7 +185,18 @@ func TestRenderFailure(t *testing.T) { } func TestRenderErrAndFailure(t *testing.T) { - r := events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis", false, false) + r := events.NewMarkdownRenderer( + false, // gitlabSupportsCommonMark + false, // disableApplyAll + false, // disableApply + false, // disableMarkdownFolding + false, // disableRepoLocking + false, // enableDiffMarkdownFormat + "", // markdownTemplateOverridesDir + "atlantis", // executableName + false, // hideUnchangedPlanComments + false, // quietPolicyChecks + ) logger := logging.NewNoopLogger(t).WithHistory() ctx := &command.Context{ Log: logger, @@ -1159,7 +1192,18 @@ $$$ }, } - r := events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis", false, false) + r := events.NewMarkdownRenderer( + false, // gitlabSupportsCommonMark + false, // disableApplyAll + false, // disableApply + false, // disableMarkdownFolding + false, // disableRepoLocking + false, // enableDiffMarkdownFormat + "", // markdownTemplateOverridesDir + "atlantis", // executableName + false, // hideUnchangedPlanComments + false, // quietPolicyChecks + ) logger := logging.NewNoopLogger(t).WithHistory() logText := "log" logger.Info(logText) @@ -1218,7 +1262,6 @@ func TestRenderProjectResultsWithQuietPolicyChecks(t *testing.T) { PolicySetResults: []models.PolicySetResult{ { PolicySetName: "policy1", - // strings.Repeat require to get wrapped result PolicyOutput: `FAIL - - main - WARNING: Null Resource creation is prohibited. 2 tests, 1 passed, 0 warnings, 1 failure, 0 exceptions`, @@ -1227,10 +1270,9 @@ func TestRenderProjectResultsWithQuietPolicyChecks(t *testing.T) { }, { PolicySetName: "policy2", - // strings.Repeat require to get wrapped result - PolicyOutput: "2 tests, 2 passed, 0 warnings, 0 failure, 0 exceptions", - Passed: true, - ReqApprovals: 1, + PolicyOutput: "2 tests, 2 passed, 0 warnings, 0 failure, 0 exceptions", + Passed: true, + ReqApprovals: 1, }, }, LockURL: "lock-url", @@ -1524,7 +1566,18 @@ $$$ }, } - r := events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis", false, true) + r := events.NewMarkdownRenderer( + false, // gitlabSupportsCommonMark + false, // disableApplyAll + false, // disableApply + false, // disableMarkdownFolding + false, // disableRepoLocking + false, // enableDiffMarkdownFormat + "", // markdownTemplateOverridesDir + "atlantis", // executableName + false, // hideUnchangedPlanComments + true, // quietPolicyChecks + ) logger := logging.NewNoopLogger(t).WithHistory() logText := "log" logger.Info(logText) @@ -1721,7 +1774,7 @@ $$$ false, // disableMarkdownFolding false, // disableRepoLocking false, // enableDiffMarkdownFormat - "", // MarkdownTemplateOverridesDir + "", // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -1906,7 +1959,7 @@ $$$ false, // disableMarkdownFolding false, // disableRepoLocking false, // enableDiffMarkdownFormat - "", // MarkdownTemplateOverridesDir + "", // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -1965,7 +2018,7 @@ func TestRenderCustomPolicyCheckTemplate_DisableApplyAll(t *testing.T) { false, // disableMarkdownFolding false, // disableRepoLocking false, // enableDiffMarkdownFormat - tmpDir, // MarkdownTemplateOverridesDir + tmpDir, // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -2040,7 +2093,7 @@ func TestRenderProjectResults_DisableFolding(t *testing.T) { true, // disableMarkdownFolding false, // disableRepoLocking false, // enableDiffMarkdownFormat - "", // MarkdownTemplateOverridesDir + "", // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -2150,7 +2203,7 @@ func TestRenderProjectResults_WrappedErr(t *testing.T) { false, // disableMarkdownFolding false, // disableRepoLocking false, // enableDiffMarkdownFormat - "", // MarkdownTemplateOverridesDir + "", // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -2296,7 +2349,7 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { false, // disableMarkdownFolding false, // disableRepoLocking false, // enableDiffMarkdownFormat - "", // MarkdownTemplateOverridesDir + "", // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -2447,7 +2500,7 @@ func TestRenderProjectResults_MultiProjectApplyWrapped(t *testing.T) { false, // disableMarkdownFolding false, // disableRepoLocking false, // enableDiffMarkdownFormat - "", // MarkdownTemplateOverridesDir + "", // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -2527,7 +2580,7 @@ func TestRenderProjectResults_MultiProjectPlanWrapped(t *testing.T) { false, // disableMarkdownFolding false, // disableRepoLocking false, // enableDiffMarkdownFormat - "", // MarkdownTemplateOverridesDir + "", // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -2754,7 +2807,7 @@ This plan was not saved because one or more projects failed and automerge requir false, // disableMarkdownFolding false, // disableRepoLocking false, // enableDiffMarkdownFormat - "", // MarkdownTemplateOverridesDir + "", // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -3311,7 +3364,7 @@ $$$ false, // disableMarkdownFolding true, // disableRepoLocking false, // enableDiffMarkdownFormat - "", // MarkdownTemplateOverridesDir + "", // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -3449,7 +3502,7 @@ $$$ false, // disableMarkdownFolding true, // disableRepoLocking false, // enableDiffMarkdownFormat - "", // MarkdownTemplateOverridesDir + "", // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -3909,7 +3962,7 @@ func TestRenderProjectResultsWithEnableDiffMarkdownFormat(t *testing.T) { false, // disableMarkdownFolding false, // disableRepoLocking true, // enableDiffMarkdownFormat - "", // MarkdownTemplateOverridesDir + "", // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -3965,7 +4018,7 @@ func BenchmarkRenderProjectResultsWithEnableDiffMarkdownFormat(b *testing.B) { false, // disableMarkdownFolding false, // disableRepoLocking true, // enableDiffMarkdownFormat - "", // MarkdownTemplateOverridesDir + "", // markdownTemplateOverridesDir "atlantis", // executableName false, // hideUnchangedPlanComments false, // quietPolicyChecks @@ -4171,7 +4224,18 @@ Ran Plan for 3 projects: }, } - r := events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis", true, false) + r := events.NewMarkdownRenderer( + false, // gitlabSupportsCommonMark + false, // disableApplyAll + false, // disableApply + false, // disableMarkdownFolding + false, // disableRepoLocking + false, // enableDiffMarkdownFormat + "", // markdownTemplateOverridesDir + "atlantis", // executableName + true, // hideUnchangedPlanComments + false, // quietPolicyChecks + ) logger := logging.NewNoopLogger(t).WithHistory() logText := "log" logger.Info(logText)