Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Extract tag if attached to Api level tags (#795)
Browse files Browse the repository at this point in the history
* Extract tag in case api.tags contains

Co-authored-by: Farhad Alizada <falizada@microsoft.com>
  • Loading branch information
f-alizada and Farhad Alizada committed Aug 19, 2022
1 parent 61bfb9f commit d134de4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public async Task<Template<TagTemplateResources>> GenerateTagsTemplateAsync(
// or if it is found in tags associated with the products associated with the api
if (string.IsNullOrEmpty(singleApiName)
|| apiOperationTagResources.Any(t => t.Name.Contains($"/{tagOriginalName}'"))
|| apiTemplateResources.Tags.Any(t => t.Name.Contains($"/{tagOriginalName}'"))
|| productAPIResources.Any(t => t.Name.Contains($"/{singleApiName}"))
&& productTagResources.Any(t => t.Name.Contains($"/{tagOriginalName}'")))
{
Expand Down
69 changes: 69 additions & 0 deletions tests/ArmTemplates.Tests/Extractor/Scenarios/TagExtractorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,74 @@ public async Task GenerateTagTemplates_GetApiOperationRelated_ProperlyLaysTheInf
resources.Tags.Any(x => x.Name.Contains(MockTagClient.OperationTagName1)).Should().BeTrue();
resources.Tags.Any(x => x.Name.Contains(MockTagClient.OperationTagName2)).Should().BeTrue();
}

[Fact]
public async Task GenerateTagTemplates_GetApiRelatedTags_ProperlyLaysTheInformation()
{
// arrange
var currentTestDirectory = Path.Combine(this.OutputDirectory, nameof(GenerateTagTemplates_GetApiRelatedTags_ProperlyLaysTheInformation));

var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration();
var extractorParameters = new ExtractorParameters(extractorConfig);

var mockedTagClient = MockTagClient.GetMockedApiClientWithDefaultValues();
var tagExtractor = new TagExtractor(
this.GetTestLogger<TagExtractor>(),
mockedTagClient,
new TemplateBuilder());

var extractorExecutor = ExtractorExecutor.BuildExtractorExecutor(
this.GetTestLogger<ExtractorExecutor>(),
tagExtractor: tagExtractor);
extractorExecutor.SetExtractorParameters(extractorParameters);

var apiTemplateResources = new ApiTemplateResources
{
Tags = new List<TagTemplateResource>
{
new TagTemplateResource
{
Name = $"parameters'/{MockTagClient.TagName1}'"
},
new TagTemplateResource
{
Name = $"parameters/{MockTagClient.TagName2}'"
}
},
ApiOperationsTags = new List<TagTemplateResource>
{
new TagTemplateResource
{
Name = $"parameters'/{MockTagClient.OperationTagName1}'"
},
new TagTemplateResource
{
Name = $"parameters/{MockTagClient.OperationTagName2}'"
}
}
};
var productTemplateResources = new ProductTemplateResources();

var tagTemplate = await extractorExecutor.GenerateTagTemplateAsync(
"apiName1",
apiTemplateResources,
productTemplateResources,
currentTestDirectory);

// assert
File.Exists(Path.Combine(currentTestDirectory, extractorParameters.FileNames.Tags)).Should().BeTrue();

tagTemplate.Parameters.Should().ContainKey(ParameterNames.ApimServiceName);
tagTemplate.TypedResources.Tags.Count().Should().Be(4);
tagTemplate.Resources.Count().Should().Be(4);

var resources = tagTemplate.TypedResources;

resources.Tags.Any(x => x.Name.Contains($"/{MockTagClient.OperationTagName1}'")).Should().BeTrue();
resources.Tags.Any(x => x.Name.Contains($"/{MockTagClient.OperationTagName2}'")).Should().BeTrue();
resources.Tags.Any(x => x.Name.Contains($"/{MockTagClient.TagName1}'")).Should().BeTrue();
resources.Tags.Any(x => x.Name.Contains($"/{MockTagClient.TagName2}'")).Should().BeTrue();
}

}
}

0 comments on commit d134de4

Please sign in to comment.