You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
provs/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/web/base/WebKtTest.kt

69 lines
2.2 KiB
Kotlin

package org.domaindrivenarchitecture.provs.framework.ubuntu.web.base
import org.domaindrivenarchitecture.provs.framework.ubuntu.web.base.downloadFromURL
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createFile
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.fileContent
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.fileExists
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
internal class WebKtTest {
@ContainerTest
@Test
fun downloadFromURL_downloadsFile() {
// given
val a = defaultTestContainer()
val file = "file1"
a.createFile("/tmp/" + file, "hello")
// when
val res = a.downloadFromURL("file:///tmp/" + file, "file2", "/tmp")
// then
val res2 = a.fileContent("/tmp/file2")
assertTrue(res.success)
assertEquals("hello", res2)
}
@ContainerTest
@Test
fun downloadFromURL_local_file_with_correct_checksum() {
// given
val a = defaultTestContainer()
val srcFile = "file3.txt"
val targetFile = "file3b.txt"
a.createFile("/tmp/" + srcFile, "hello")
// when
val res = a.downloadFromURL("file:///tmp/" + srcFile, targetFile, "tmp", sha256sum ="2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824") // ubuntu 20.04 sha256sum version 8.30
// then
val res2 = a.fileContent("tmp/$targetFile")
assertEquals("hello", res2)
assertTrue(res.success)
}
@ContainerTest
@Test
fun downloadFromURL_local_file_with_incorrect_checksum() {
// given
val a = defaultTestContainer()
val srcFile = "file3.txt"
val targetFile = "file3b.txt"
a.createFile("/tmp/" + srcFile, "hello")
// when
val res = a.downloadFromURL("file:///tmp/" + srcFile, targetFile, "tmp", sha256sum = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824WRONG")
// then
val res2 = a.fileExists("tmp/$targetFile")
assertFalse(res.success)
assertFalse(res2)
}
}