src/test/kotlin/de/uapcore/lightpit/vcs/HgConnectorTest.kt

Tue, 18 Jul 2023 18:05:49 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 18 Jul 2023 18:05:49 +0200
changeset 280
12b898531d1a
parent 279
d73537b925af
permissions
-rw-r--r--

add working Mercurial commit log parser

fixes #274

     1 /*
     2  * Copyright 2023 Mike Becker. All rights reserved.
     3  *
     4  * Redistribution and use in source and binary forms, with or without
     5  * modification, are permitted provided that the following conditions are met:
     6  *
     7  * 1. Redistributions of source code must retain the above copyright
     8  * notice, this list of conditions and the following disclaimer.
     9  *
    10  * 2. Redistributions in binary form must reproduce the above copyright
    11  * notice, this list of conditions and the following disclaimer in the
    12  * documentation and/or other materials provided with the distribution.
    13  *
    14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    17  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    20  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    21  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    22  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    24  *
    25  */
    27 package de.uapcore.lightpit.vcs
    29 import kotlin.io.path.Path
    30 import kotlin.io.path.absolutePathString
    31 import kotlin.io.path.exists
    32 import kotlin.io.path.moveTo
    33 import kotlin.test.*
    35 class HgConnectorTest {
    37     private val testee = HgConnector("/usr/bin/hg")
    38     private val testRepoPath = Path("src/test/resources/test-repo")
    40     @BeforeTest
    41     fun prepareTestRepo() {
    42         assertTrue(testRepoPath.exists(), "Test must be run from the project root.")
    43         val hg = testRepoPath.resolve("hg")
    44         val dothg = testRepoPath.resolve(".hg")
    45         assertTrue(hg.exists(), "hg dir not found, maybe a previous execution did not terminated cleanly.")
    46         assertFalse(dothg.exists(), ".hg dir found, maybe a previous execution did not terminated cleanly.")
    47         hg.moveTo(dothg)
    48     }
    50     @AfterTest
    51     fun cleanup() {
    52         val hg = testRepoPath.resolve("hg")
    53         val dothg = testRepoPath.resolve(".hg")
    54         dothg.moveTo(hg)
    55     }
    57     @Test
    58     fun checkAvailability() {
    59         assertTrue(testee.checkAvailability())
    60     }
    62     @Test
    63     fun checkAvailabilityFalse() {
    64         assertFalse(HgConnector("/bin/false").checkAvailability())
    65     }
    67     @Test
    68     fun readCommitLog() {
    69         val result = testee.readCommitLog(testRepoPath.absolutePathString())
    70         assertTrue(result is VcsConnectorResult.Success)
    72         assertContentEquals(
    73             listOf(
    74                 CommitRef("cf9f5982ddeb28c7f695dc547fe73abf5460016f", 50, "here we fix #50"),
    75                 CommitRef("cf9f5982ddeb28c7f695dc547fe73abf5460016f", 30, "here we fix #50"),
    76                 CommitRef(
    77                     "ed7134e5f4ce278c4f62798fb9f96129be2b132b",
    78                     1337,
    79                     "commit with a #non-ref, relates to #wrong ref but still fixes #1337"
    80                 ),
    81                 CommitRef("74d770da3c80c0c3fc1fb7e44fb710d665127dfe", 47, "a change with commitref in body"),
    82                 CommitRef("9a14e5628bdf2d578f3385d78022ddcaf23d1abb", 47, "add test file - relates to #47")
    83             ),
    84             result.content
    85         )
    86     }
    87 }

mercurial