Skip to content

Commit

Permalink
Add test for hashFilesDetailed
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Aug 7, 2020
1 parent cc7a294 commit ce7fa0f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
11 changes: 10 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ allprojects {

kotlin {
js {
browser()
browser {
testTask {
useMocha()
testLogging {
showStandardStreams = true
}
}
}
binaries.executable()
}
}
Expand All @@ -27,4 +34,6 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${"kotlinx-coroutines".v}")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${"kotlinx-serialization".v}")
implementation(project(":lib"))

testImplementation(kotlin("test-js"))
}
5 changes: 5 additions & 0 deletions src/main/kotlin/com/github/burrunan/gradle/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ package com.github.burrunan.gradle
import com.github.burrunan.gradle.github.env.ActionsEnvironment
import com.github.burrunan.gradle.github.event.currentTrigger
import github.actions.core.info
import process

internal fun getInput(name: String, required: Boolean = false): String =
github.actions.core.getInput(name, jsObject { this.required = required })

suspend fun main() {
if (process.env["GITHUB_ACTIONS"].isNullOrBlank()) {
// Ignore if called outside of GitHub Actions (e.g. tests)
return
}
val params = Parameters(
jobId = ActionsEnvironment.RUNNER_OS + "-" + getInput("job-id"),
path = getInput("path").trimEnd('/', '\\').ifBlank { "." },
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/fs2/promises/fspromises.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ external fun writeFile(path: String, data: Any, encoding: String): Promise<Unit>
external fun stat(path: String): Promise<fs.Stats>

external fun rename(oldPath: String, newPath: String): Promise<Unit>

external fun mkdir(path: String): Promise<Unit>

external fun writeFile(path: String, data: Any, options: String? = definedExternally): Promise<Unit>
30 changes: 30 additions & 0 deletions src/test/kotlin/com/github/burrunan/gradle/GlobTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.burrunan.gradle

import com.github.burrunan.gradle.github.formatBytes
import com.github.burrunan.gradle.hashing.hashFilesDetailed
import kotlinx.coroutines.await
import runTest
import kotlin.test.Test
import kotlin.test.assertEquals

class GlobTest {
@Test
fun glob() = runTest {
val dirName = "globTest"
if (!exists(dirName)) {
fs2.promises.mkdir(dirName).await()
}
fs2.promises.writeFile("$dirName/good.txt", "a", "utf8")
fs2.promises.writeFile("$dirName/bad.txt", "a", "utf8")

val hash = hashFilesDetailed(
"**/*.txt",
"!**/*bad**",
)
println("${hash.info.totalBytes.formatBytes()} ${hash.info.totalFiles} files")
val actual = hash.contents.files.entries.joinToString { (file, details) ->
"${details.fileSize.formatBytes()} ${details.hash} $file"
}
assertEquals("1 B 86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 ws:///globTest/good.txt", actual)
}
}
7 changes: 7 additions & 0 deletions src/test/kotlin/com/github/burrunan/gradle/runTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.promise

fun runTest(block: suspend () -> Unit): dynamic = GlobalScope.promise {
process.env["RUNNER_OS"] = "macos"
block()
}

0 comments on commit ce7fa0f

Please sign in to comment.