-
Notifications
You must be signed in to change notification settings - Fork 319
Migrate metadata/supported-configurations.json from V1 to V2 Format.
#10078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
buildSrc/src/test/kotlin/datadog/gradle/plugin/config/ParseV2SupportedConfigurationsTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| package datadog.gradle.plugin.config | ||
|
|
||
| import org.gradle.testkit.runner.BuildResult | ||
| import org.gradle.testkit.runner.GradleRunner | ||
| import org.gradle.testkit.runner.TaskOutcome | ||
| import org.junit.jupiter.api.Assertions.assertEquals | ||
| import org.junit.jupiter.api.Assertions.assertTrue | ||
| import org.junit.jupiter.api.Test | ||
| import org.junit.jupiter.api.io.TempDir | ||
| import java.io.File | ||
| import java.nio.file.Paths | ||
|
|
||
| class ParseV2SupportedConfigurationsTest { | ||
| @Test | ||
| fun `should generate Java file from JSON configuration`(@TempDir projectDir: File) { | ||
| val (buildResult, generatedFile) = runGradleTask(projectDir) | ||
|
|
||
| assertEquals(TaskOutcome.SUCCESS, buildResult.task(":generateSupportedConfigurations")?.outcome) | ||
|
|
||
| assertTrue(generatedFile.exists(), "Generated Java file should exist") | ||
|
|
||
| val content = generatedFile.readText() | ||
| assertTrue(content.contains("package datadog.test;")) | ||
| assertTrue(content.contains("public final class TestGeneratedSupportedConfigurations {")) | ||
|
|
||
| assertTrue(content.contains("public static final Map<String, List<SupportedConfiguration>> SUPPORTED;")) | ||
| assertTrue(content.contains("public static final Map<String, List<String>> ALIASES;")) | ||
| assertTrue(content.contains("public static final Map<String, String> ALIAS_MAPPING;")) | ||
| assertTrue(content.contains("public static final Map<String, String> DEPRECATED;")) | ||
| assertTrue(content.contains("public static final Map<String, String> REVERSE_PROPERTY_KEYS_MAP;")) | ||
|
|
||
| assertTrue(content.contains("private static Map<String, List<SupportedConfiguration>> initSupported()")) | ||
| assertTrue(content.contains("private static void initSupported1(Map<String, List<SupportedConfiguration>> supportedMap)")) | ||
| assertTrue(content.contains("private static void initSupported2(Map<String, List<SupportedConfiguration>> supportedMap)")) | ||
| assertTrue(content.contains("private static Map<String, List<String>> initAliases()")) | ||
| assertTrue(content.contains("private static Map<String, String> initAliasMapping()")) | ||
| assertTrue(content.contains("private static Map<String, String> initDeprecated()")) | ||
| assertTrue(content.contains("private static Map<String, String> initReversePropertyKeysMap()")) | ||
|
|
||
| assertContainsSupportedConfig( | ||
| content, | ||
| key = "DD_ACTION_EXECUTION_ID", | ||
| version = "A", | ||
| type = "string", | ||
| default = "null", | ||
| aliases = emptyList(), | ||
| propertyKeys = listOf("property.key") | ||
| ) | ||
|
|
||
| assertContainsSupportedConfig( | ||
| content, | ||
| key = "DD_AGENTLESS_LOG_SUBMISSION_ENABLED", | ||
| version = "A", | ||
| type = "boolean", | ||
| default = "false", | ||
| aliases = emptyList() | ||
| ) | ||
|
|
||
| assertContainsSupportedConfig( | ||
| content, | ||
| key = "DD_AGENTLESS_LOG_SUBMISSION_ENABLED", | ||
| version = "B", | ||
| type = "boolean", | ||
| default = "true", | ||
| aliases = listOf("DD_ALIAS") | ||
| ) | ||
|
|
||
| assertTrue(content.contains("""aliasesMap.put("DD_ACTION_EXECUTION_ID", Collections.unmodifiableList(Arrays.asList()))""")) | ||
| assertTrue(content.contains("""aliasesMap.put("DD_AGENTLESS_LOG_SUBMISSION_ENABLED", Collections.unmodifiableList(Arrays.asList("DD_ALIAS")))""")) | ||
|
|
||
| assertTrue(content.contains("""aliasMappingMap.put("DD_ALIAS", "DD_AGENTLESS_LOG_SUBMISSION_ENABLED")""")) | ||
|
|
||
| assertTrue(content.contains("""deprecatedMap.put("old.config", "Use test.config instead")""")) | ||
| assertTrue(content.contains("""deprecatedMap.put("legacy.setting", "No longer supported")""")) | ||
|
|
||
| assertTrue(content.contains("""reversePropertyKeysMapping.put("property.key", "DD_ACTION_EXECUTION_ID")""")) | ||
| } | ||
|
|
||
| private fun runGradleTask(projectDir: File): Pair<BuildResult, File> { | ||
| val jsonFile = file(projectDir, "test-supported-configurations.json") | ||
| jsonFile.writeText( | ||
| """ | ||
| { | ||
| "supportedConfigurations": { | ||
| "DD_ACTION_EXECUTION_ID": [ | ||
| { | ||
| "version": "A", | ||
| "type": "string", | ||
| "default": null, | ||
| "aliases": [], | ||
| "propertyKeys": ["property.key"] | ||
| } | ||
| ], | ||
| "DD_AGENTLESS_LOG_SUBMISSION_ENABLED": [ | ||
| { | ||
| "version": "A", | ||
| "type": "boolean", | ||
| "default": "false", | ||
| "aliases": [] | ||
| }, | ||
| { | ||
| "version": "B", | ||
| "type": "boolean", | ||
| "default": "true", | ||
| "aliases": ["DD_ALIAS"] | ||
| } | ||
| ] | ||
| }, | ||
| "deprecations": { | ||
| "old.config": "Use test.config instead", | ||
| "legacy.setting": "No longer supported" | ||
| } | ||
| } | ||
| """.trimIndent() | ||
| ) | ||
|
|
||
| setupGradleProject(projectDir) | ||
|
|
||
| val buildResult = GradleRunner.create() | ||
| .forwardOutput() | ||
| .withPluginClasspath() | ||
| .withArguments("generateSupportedConfigurations") | ||
| .withProjectDir(projectDir) | ||
| .build() | ||
|
|
||
| val generatedFile = file(projectDir, "build", "generated", "supportedConfigurations", "datadog", "test", "TestGeneratedSupportedConfigurations.java") | ||
| return Pair(buildResult, generatedFile) | ||
| } | ||
|
|
||
| private fun setupGradleProject(projectDir: File) { | ||
| file(projectDir, "settings.gradle.kts").writeText( | ||
| """ | ||
| rootProject.name = "test-config-project" | ||
| """.trimIndent() | ||
| ) | ||
|
|
||
| file(projectDir, "build.gradle.kts").writeText( | ||
| """ | ||
| plugins { | ||
| id("java") | ||
| id("dd-trace-java.supported-config-generator") | ||
| } | ||
|
|
||
| group = "datadog.config.test" | ||
|
|
||
| supportedTracerConfigurations { | ||
| jsonFile.set(file("test-supported-configurations.json")) | ||
| destinationDirectory.set(file("build/generated/supportedConfigurations")) | ||
| className.set("datadog.test.TestGeneratedSupportedConfigurations") | ||
| } | ||
| """.trimIndent() | ||
| ) | ||
| } | ||
|
|
||
| private fun file(projectDir: File, vararg parts: String, makeDirectory: Boolean = false): File { | ||
| val f = Paths.get(projectDir.absolutePath, *parts).toFile() | ||
|
|
||
| if (makeDirectory) { | ||
| f.parentFile.mkdirs() | ||
| } | ||
|
|
||
| return f | ||
| } | ||
|
|
||
| private fun assertContainsSupportedConfig( | ||
| content: String, | ||
| key: String, | ||
| version: String, | ||
| type: String, | ||
| default: String, | ||
| aliases: List<String>, | ||
| propertyKeys: List<String> = emptyList() | ||
| ) { | ||
| val aliasesArray = aliases.joinToString(", ") { "\"$it\"" } | ||
| val propertyKeysArray = propertyKeys.joinToString(", ") { "\"$it\"" } | ||
|
|
||
| assertTrue( | ||
| content.contains("""supportedMap.put("$key""""), | ||
| "Should contain supportedMap.put for key: $key" | ||
| ) | ||
|
|
||
| val expectedPattern = buildString { | ||
| append("new SupportedConfiguration(") | ||
| append("\"$version\", ") | ||
| append("\"$type\", ") | ||
| append(if (default == "null") "null" else "\"$default\"") | ||
| append(", ") | ||
| append("Arrays.asList($aliasesArray)") | ||
| append(", ") | ||
| append("Arrays.asList($propertyKeysArray)") | ||
| append(")") | ||
| } | ||
|
|
||
| assertTrue( | ||
| content.contains(expectedPattern), | ||
| "Should contain SupportedConfiguration: $expectedPattern" | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.