public async Task UpdateEnvFileDocumentation_should_not_update_when_section_does_not_exist() { _readmeEditor.ExtractReadmeContent().ReturnsForAnyArgs( "## Existing Section" + Environment.NewLine + "with a paragraph, and some text" + Environment.NewLine); var envSuccess = await _updater.UpdateDocumentation(new EnvVarDocumentationUpdater()); envSuccess.Should().BeFalse(); var awsSuccess = await _updater.UpdateDocumentation(new AwsDocumentationUpdater("Test/Assembly")); awsSuccess.Should().BeFalse(); }
public async Task <bool> UpdateDocumentation <T>(IDocumentationUpdater <T> updater) where T : ConfigurationParameterAttribute { try { var expectedEnvVarSecrets = GetExpectedEnvVarSecretsFromLoadedAssemblies <T>(updater.ParametersPrefix, updater.ParametersSuffix); if (!expectedEnvVarSecrets.Any()) { return(true); } var readmeContent = await _editor.ExtractReadmeContent(); var secretsMentionedInReadme = updater.SectionToUpdateRegex.Match(readmeContent); if (!secretsMentionedInReadme.Success) { var stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Your README.md file should contain the following section:"); updater.AppendSection(stringBuilder, expectedEnvVarSecrets); _output.WriteLine(stringBuilder.ToString()); return(false); } var contentToReplace = secretsMentionedInReadme.Groups["params"].Value; var knownSecrets = secretsMentionedInReadme.Groups["params"].Value.Split(Environment.NewLine).Where(s => !string.IsNullOrWhiteSpace(s)); var allSecrets = expectedEnvVarSecrets.Union(knownSecrets).Distinct().OrderBy(s => s); var newContent = string.Join(Environment.NewLine, allSecrets) + Environment.NewLine; var newReadmeContent = readmeContent.Replace(contentToReplace, newContent, StringComparison.InvariantCulture); await _editor.UpdateReadmeContent(newReadmeContent).ConfigureAwait(false); return(true); } catch (Exception e) { _output.WriteLine("Failed to update env file documentation."); _output.WriteLine(e.ToString()); return(false); } }