package invalid.lena.rsend

import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test

class RsyncRunnerTest {

    private val remote = Remote("host", 22, "user")

    @Test
    fun basicArgs() {
        val a = RsyncRunner.args("RSH", remote, Folder(name = "n", local = "/a", remote = "/b"))
        assertEquals(
            listOf(
                "-rt", "--partial", "--timeout=300",
                "--no-perms", "--no-owner", "--no-group", "--omit-dir-times",
                "-e", "RSH", "/a/", "user@host:/b/",
            ),
            a,
        )
    }

    @Test
    fun mirrorAddsDelete() {
        val a = RsyncRunner.args("RSH", remote, Folder(local = "/a", remote = "/b", delete = true))
        assertTrue(a.contains("--delete"))
    }

    @Test
    fun additiveOmitsDelete() {
        val a = RsyncRunner.args("RSH", remote, Folder(local = "/a", remote = "/b", delete = false))
        assertTrue(!a.contains("--delete"))
    }

    @Test
    fun excludesBecomeFlags() {
        val a = RsyncRunner.args("RSH", remote, Folder(local = "/a", remote = "/b", excludes = listOf(".x/", ".y")))
        assertTrue(a.contains("--exclude=.x/"))
        assertTrue(a.contains("--exclude=.y"))
    }

    @Test
    fun trailingSlashIdempotent() {
        val a = RsyncRunner.args("RSH", remote, Folder(local = "/a/", remote = "/b/"))
        assertTrue(a.contains("/a/"))
        assertTrue(a.contains("user@host:/b/"))
    }
}
