-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(itest): add test for UploadPackageTask with wait
- Loading branch information
1 parent
fac2471
commit 922a9cb
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
...ionTest/kotlin/com/liftric/octopusdeploy/task/UploadPackageTaskWithWaitIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.liftric.octopusdeploy.task | ||
|
||
import com.liftric.octopusdeploy.apiKey | ||
import com.liftric.octopusdeploy.getPackageResponse | ||
import com.liftric.octopusdeploy.serverUrl | ||
import junit.framework.TestCase.assertEquals | ||
import junit.framework.TestCase.assertNotNull | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
import kotlin.random.Random | ||
|
||
class UploadPackageTaskWithWaitIntegrationTest { | ||
@get:Rule | ||
val testProjectDir = TemporaryFolder() | ||
|
||
@Test | ||
fun testExecute() { | ||
val major = Random.Default.nextInt(0, 100) | ||
val minor = Random.Default.nextInt(0, 100) | ||
val micro = Random.Default.nextInt(0, 100) | ||
println(testProjectDir.root.absolutePath) | ||
setupBuild(major, minor, micro) | ||
|
||
val result = GradleRunner.create() | ||
.forwardOutput() | ||
.withProjectDir(testProjectDir.root) | ||
.withArguments("build", "uploadPackage") | ||
.withPluginClasspath() | ||
.build() | ||
println(result.output) | ||
assertEquals(TaskOutcome.SUCCESS, result.task(":uploadPackage")?.outcome) | ||
|
||
val packageItem = getPackageResponse() | ||
.items | ||
?.filter { | ||
it.version == "$major.$minor.$micro" | ||
} | ||
?.firstOrNull() | ||
assertNotNull(packageItem) | ||
assertEquals(".jar", packageItem?.fileExtension) | ||
|
||
val secondResult = GradleRunner.create() | ||
.forwardOutput() | ||
.withProjectDir(testProjectDir.root) | ||
.withArguments("build", "uploadPackage") | ||
.withPluginClasspath() | ||
.buildAndFail() | ||
println(secondResult.output) | ||
// override is not set | ||
assertEquals(TaskOutcome.FAILED, secondResult.task(":uploadPackage")?.outcome) | ||
} | ||
|
||
fun setupBuild(major: Int, minor: Int, micro: Int) { | ||
testProjectDir.newFile("build.gradle.kts").apply { | ||
writeText( | ||
""" | ||
import com.liftric.octopusdeploy.task.UploadPackageTask | ||
plugins { | ||
java | ||
id("com.liftric.octopus-deploy-plugin") | ||
} | ||
group = "com.liftric.test" | ||
version = "$major.$minor.$micro" | ||
tasks { | ||
withType<Jar> { | ||
archiveFileName.set( | ||
"${'$'}{archiveBaseName.get() | ||
.removeSuffix("-")}.${'$'}{archiveVersion.get()}.${'$'}{archiveExtension.get()}" | ||
) | ||
} | ||
withType<UploadPackageTask>{ | ||
waitForReleaseDeployments.set(true) | ||
waitTimeoutSeconds.set(1L) | ||
delayBetweenChecksSeconds.set(2L) | ||
httpLogLevel.set(okhttp3.logging.HttpLoggingInterceptor.Level.HEADERS) | ||
} | ||
} | ||
octopus { | ||
serverUrl.set("$serverUrl") | ||
apiKey.set("$apiKey") | ||
generateChangelogSinceLastTag = true | ||
val jar by tasks.existing(Jar::class) | ||
packageName.set(jar.get().archiveBaseName.get().removeSuffix("-")) | ||
version.set(jar.get().archiveVersion.get()) | ||
pushPackage.set(jar.get().archiveFile) | ||
} | ||
""" | ||
) | ||
} | ||
testProjectDir.root.setupGitRepoCopy() | ||
} | ||
} |