forked from unbroken-dome/gradle-helm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Citi/verifyVersions
Verify versions
- Loading branch information
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
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
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
52 changes: 52 additions & 0 deletions
52
helm-plugin/src/test/kotlin/com/citi/gradle/plugins/helm/PluginVersionSynchronization.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,52 @@ | ||
package com.citi.gradle.plugins.helm | ||
|
||
import io.kotest.matchers.string.shouldContain | ||
import java.io.File | ||
import java.util.Properties | ||
import org.junit.jupiter.api.Test | ||
|
||
class PluginVersionSynchronization { | ||
|
||
/** | ||
* This verification is needed before https://github.com/Citi/gradle-helm-plugin/issues/24 is implemented to have the same plugin version with documentation | ||
*/ | ||
@Test | ||
fun pluginVersionShouldBeTheSameWithDocumentation() { | ||
val pluginVersion = getPluginVersion() | ||
val expectedDocumentationLine = ":version: $pluginVersion" | ||
|
||
val readmeFile = File("../README.adoc").absoluteFile.readText() | ||
|
||
readmeFile shouldContain expectedDocumentationLine | ||
} | ||
|
||
private fun getPluginVersion(): Version { | ||
val gradleProperties = Properties().apply { | ||
File("../gradle.properties").absoluteFile.reader().use { fileReader -> | ||
load(fileReader) | ||
} | ||
} | ||
|
||
val pluginVersion = gradleProperties.getProperty("version") | ||
|
||
return Version.parse(pluginVersion) | ||
} | ||
|
||
private data class Version(val major: Int, val minor: Int, val revision: Int) { | ||
companion object { | ||
fun parse(input: String): Version { | ||
val fragments = input.split('.') | ||
|
||
require(fragments.size == 3) { | ||
"Fragment count should be 3, but was ${fragments.size}: $input" | ||
} | ||
|
||
return Version(fragments[0].toInt(), fragments[1].toInt(), fragments[2].toInt()) | ||
} | ||
} | ||
|
||
override fun toString(): String { | ||
return "$major.$minor.$revision" | ||
} | ||
} | ||
} |