Skip to content

Commit

Permalink
Create new test using GradleRunner that actually tests toGDrive copy
Browse files Browse the repository at this point in the history
  • Loading branch information
itsnotoger committed Oct 13, 2024
1 parent 2e9121d commit efc23e0
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/test/groovy/oger.util.java/ToGDriveSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package oger.util.java


import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import spock.lang.Specification
import spock.lang.TempDir

class ToGDriveSpec extends Specification {

@TempDir
File testProjectDir
File settingsFile
File buildFile
File outJar

def setup() {
settingsFile = new File(testProjectDir, 'settings.gradle')
buildFile = new File(testProjectDir, 'build.gradle')

// use this to test real path and remove environment below: def basePath = [email protected]()
def basePath = testProjectDir.toPath()
outJar = basePath.resolve("syncme/gradle_jars/oger.test.jar").toFile()
outJar.delete()
}

def cleanup() {
outJar.delete()
}

def "actually copies files with toGDrive"() {
given:
settingsFile << "rootProject.name = 'oger.test'"
buildFile << """
plugins {
id 'com.github.itsnotoger.gradle-plugin'
}
gdrive {
debug = true
type = oger.util.java.Type.JARLIBRARY
GDriveJars = "/syncme/gradle_jars"
GDriveApps = "/gradle_apps"
mainClass = "oger.util.java.OgerPluginSpec"
}
"""

when:
def result = GradleRunner.create()
.withProjectDir(testProjectDir)
.withArguments('toGDrive')
.withPluginClasspath()
.withEnvironment(Map.of("GDRIVE", testProjectDir.toString()))
.build()

println getClass().getSimpleName() + " test build output { \n\t" + result.output.split("\n").join("\n\t") + "}"

then:
result.output.contains('toGDrive')
result.task(":toGDrive").outcome == TaskOutcome.SUCCESS
outJar.exists()
}
}

0 comments on commit efc23e0

Please sign in to comment.