|
| 1 | +package io.miret.etienne.gradle.sass; |
| 2 | + |
| 3 | +import com.github.tomakehurst.wiremock.WireMockServer; |
| 4 | +import com.google.common.collect.ImmutableList; |
| 5 | +import org.assertj.core.api.SoftAssertions; |
| 6 | +import org.assertj.core.api.junit.jupiter.InjectSoftAssertions; |
| 7 | +import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension; |
| 8 | +import org.gradle.testkit.runner.GradleRunner; |
| 9 | +import org.junit.jupiter.api.BeforeEach; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 12 | +import org.junit.jupiter.api.io.TempDir; |
| 13 | + |
| 14 | +import java.io.IOException; |
| 15 | +import java.nio.file.Path; |
| 16 | +import java.util.List; |
| 17 | + |
| 18 | +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
| 19 | +import static com.github.tomakehurst.wiremock.client.WireMock.get; |
| 20 | +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; |
| 21 | +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; |
| 22 | +import static io.miret.etienne.gradle.sass.Utils.copy; |
| 23 | +import static io.miret.etienne.gradle.sass.Utils.createArchive; |
| 24 | +import static java.util.Collections.singletonMap; |
| 25 | + |
| 26 | +/** |
| 27 | + * Test applying this plugin in multiple subprojects |
| 28 | + * instead of only the root project. |
| 29 | + */ |
| 30 | +@ExtendWith(SoftAssertionsExtension.class) |
| 31 | +public class MultipleApplyTest { |
| 32 | + |
| 33 | + @TempDir |
| 34 | + Path projectDir; |
| 35 | + |
| 36 | + @InjectSoftAssertions |
| 37 | + private SoftAssertions softly; |
| 38 | + |
| 39 | + private WireMockServer server; |
| 40 | + |
| 41 | + @BeforeEach |
| 42 | + void startAndSetupWiremockServer () throws IOException { |
| 43 | + server = new WireMockServer(options().dynamicPort()); |
| 44 | + server.start(); |
| 45 | + server.stubFor(get(urlMatching("/42.0/dart-sass-.*")) |
| 46 | + .willReturn(aResponse() |
| 47 | + .withStatus(200) |
| 48 | + .withBody(createArchive()) |
| 49 | + ) |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + @BeforeEach |
| 54 | + void setupProject() throws IOException { |
| 55 | + List<String> projectResources = ImmutableList.of( |
| 56 | + "a/build.gradle", |
| 57 | + "b/build.gradle", |
| 58 | + "c/build.gradle", |
| 59 | + "build.gradle", |
| 60 | + "settings.gradle" |
| 61 | + ); |
| 62 | + copy("/io/miret/etienne/gradle/sass/multiple-apply", projectResources, projectDir); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + void should_not_create_dot_gradle_directories_in_subprojects() { |
| 67 | + GradleRunner runner = GradleRunner.create(); |
| 68 | + runner.withPluginClasspath(); |
| 69 | + runner.withEnvironment(singletonMap("URL", server.baseUrl())); |
| 70 | + runner.withArguments("installSass"); |
| 71 | + runner.withProjectDir(projectDir.toFile()); |
| 72 | + runner.build(); |
| 73 | + |
| 74 | + softly.assertThat(projectDir.resolve("a/.gradle")).doesNotExist(); |
| 75 | + softly.assertThat(projectDir.resolve("b/.gradle")).doesNotExist(); |
| 76 | + softly.assertThat(projectDir.resolve("c/.gradle")).doesNotExist(); |
| 77 | + } |
| 78 | + |
| 79 | +} |
0 commit comments