Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package build.extensions.oss.gradle.pluginutils


/**
* The code is used in Gradle Helm Plugin - to put proper classifier and archive format depending on operating system.
*
* Suffixes below are very common for binary distribution, so they work for other packages as well.
*/
object SystemUtils {

private val osName = System.getProperty("os.name")
private val osArch = System.getProperty("os.arch")


/**
* Returns operating system classifier for Helm package.
*/
// Suppress the error - it is easier to list all options in a one place.
@Suppress("complexity:CyclomaticComplexMethod")
fun getOperatingSystemClassifier() =
when {
osName.startsWith("Windows") ->
"windows-amd64"
osName.startsWith("Mac OS X") ->
"darwin-amd64"
when (osArch) {
"aarch64" -> "darwin-arm64"
else -> "darwin-amd64"
}
osName.startsWith("Linux") ->
when (osArch) {
"amd64" -> "linux-amd64"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package build.extensions.oss.gradle.pluginutils

import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.startWith
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS

/**
* Test if we return more or less adequate values. Basically, we can't verify that without running integration tests,
* therefore let's check that at least some values are more or less good here.
*
* We can't check (for example) it easily on ARM on GitHub.
*
* We run the same test on different operating systems,
* so we will never run all methods from this class at the same test run.
*/
class SystemUtilsTest {

@Test
@EnabledOnOs(OS.WINDOWS)
fun testWindowsClassifier() {
SystemUtils.getOperatingSystemClassifier() shouldBe "windows-amd64"
}

@Test
@EnabledOnOs(OS.LINUX)
fun testLinuxClassifier() {
SystemUtils.getOperatingSystemClassifier() should startWith("linux-")
}

@Test
@EnabledOnOs(OS.MAC)
fun testMacClassifier() {
SystemUtils.getOperatingSystemClassifier() should startWith("darwin-")
}

@Test
@EnabledOnOs(OS.WINDOWS)
fun testWindowsArchiveFormat() {
SystemUtils.getOperatingSystemArchiveFormat() shouldBe "zip"
}

@Test
@EnabledOnOs(OS.LINUX, OS.MAC)
fun testPosixArchiveFormat() {
SystemUtils.getOperatingSystemArchiveFormat() shouldBe "tar.gz"
}
}