gradle-git-properties icon indicating copy to clipboard operation
gradle-git-properties copied to clipboard

Test case for failOnNoGitDirectory not working as expected

Open g-sudheer opened this issue 1 year ago • 0 comments

Greetings,

I'm using this plugin for my project (Spring Boot App), I like this very much.

I'm writing some test cases around to make sure the plugin is working as expected , notice that the below test always returns success.

if I do not set gitPropertiesPluginExtension.failOnNoGitDirectory = true which is the default behavior , then also I see same result and if I set explicitly also I see the same behavior.

expected behavior is to catch the exception and run those asserts as there is no .git directly by default in my src/test/resources/git-properties-plugin folder.

I'm using Spring Boot 3.3.5 Gradle : 8.10.2 Java 21. Kotlin JVM : 1.9.0

@Test
    fun testPluginFailsWithoutGitDirectoryAndFailOnNoGitDirectoryTrue() {
        val projectDir = File("src/test/resources/git-properties-plugin")

        val project = ProjectBuilder.builder().withProjectDir(projectDir).build()
        project.pluginManager.apply(GitPropertiesPlugin::class.java)

        try {
           val gitPropertiesPluginExtension = project.extensions.getByType(GitPropertiesPluginExtension::class.java)
            gitPropertiesPluginExtension.failOnNoGitDirectory = true

            val gitPropertiesTask = project.tasks.getByName("generateGitProperties") as GenerateGitPropertiesTask
            gitPropertiesTask.generate()

        } catch (e: Exception) {
            assertEquals(GradleException::class.java, e::class.java)
            assertEquals("No Git repository found.", e.message)
        }

        //cleanUp(projectDir)

    }

Thanks.

g-sudheer avatar Nov 17 '24 17:11 g-sudheer