Skip to content

Commit

Permalink
Adds testResource macro to core. Fix #1526.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaLaGrotteria committed Oct 24, 2024
1 parent 0a6b4c1 commit 58fe4fb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.micronaut.guides.core;

import jakarta.inject.Singleton;

import java.util.List;

import static io.micronaut.guides.core.MacroUtils.addIncludesResources;

@Singleton
public class TestResourceMacroSubstitution implements MacroSubstitution{
@Override
public String substitute(String str, String slug, GuidesOption option) {
String resourceDir = "test";

List<String> lines = addIncludesResources(str,slug,option,resourceDir,"testResource");

return String.join("\n", lines);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.micronaut.guides.core;

import io.micronaut.starter.api.TestFramework;
import io.micronaut.starter.options.BuildTool;
import io.micronaut.starter.options.Language;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

@MicronautTest(startApplication = false)
public class TestResourceMacroSubstitutionTest {

@Inject
TestResourceMacroSubstitution testResourceMacroSubstitution;

@Test
void testSubstitute() {
String str = "testResource:app/application-test.yml[tag=testcontainers]";
String resJava = testResourceMacroSubstitution.substitute(str, "micronaut-metrics-oci", new GuidesOption(BuildTool.GRADLE, Language.JAVA, TestFramework.JUNIT));
String expectedJava = """
[source,yaml]
.src/test/resources/application-test.yml
----
include::{sourceDir}/micronaut-metrics-oci/micronaut-metrics-oci-gradle-java/src/test/resources/application-test.yml[tag=testcontainers]
----
""";
assertEquals(expectedJava, resJava);
}
}

0 comments on commit 58fe4fb

Please sign in to comment.