Skip to content
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

Test case for failOnNoGitDirectory not working as expected #236

Open
g-sudheer opened this issue Nov 17, 2024 · 0 comments
Open

Test case for failOnNoGitDirectory not working as expected #236

g-sudheer opened this issue Nov 17, 2024 · 0 comments

Comments

@g-sudheer
Copy link

g-sudheer commented Nov 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant