|
| 1 | +/* |
| 2 | + * Copyright (C) 2017 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>) |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + * License-Filename: LICENSE |
| 18 | + */ |
| 19 | + |
| 20 | +package org.ossreviewtoolkit.downloader |
| 21 | + |
| 22 | +import io.kotest.core.spec.style.WordSpec |
| 23 | +import io.kotest.matchers.nulls.beNull |
| 24 | +import io.kotest.matchers.nulls.shouldNotBeNull |
| 25 | +import io.kotest.matchers.should |
| 26 | +import io.kotest.matchers.shouldBe |
| 27 | +import io.kotest.matchers.shouldNot |
| 28 | +import io.kotest.matchers.shouldNotBe |
| 29 | + |
| 30 | +import org.ossreviewtoolkit.model.VcsType |
| 31 | +import org.ossreviewtoolkit.plugins.api.PluginConfig |
| 32 | + |
| 33 | +class VersionControlSystemFunTest : WordSpec({ |
| 34 | + "forUrl()" should { |
| 35 | + "return null for an unsupported repository URL" { |
| 36 | + val repositoryUrl = "https://example.com" |
| 37 | + |
| 38 | + val vcs = VersionControlSystem.forUrl(repositoryUrl) |
| 39 | + |
| 40 | + vcs should beNull() |
| 41 | + } |
| 42 | + |
| 43 | + "return a VCS instance that can handle a Git repository URL" { |
| 44 | + val repositoryUrl = "https://github.com/oss-review-toolkit/ort.git" |
| 45 | + |
| 46 | + val vcs = VersionControlSystem.forUrl(repositoryUrl) |
| 47 | + |
| 48 | + vcs shouldNotBeNull { |
| 49 | + type shouldBe VcsType.GIT |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + "return the VCS instance with the correct configuration from cache" { |
| 54 | + val repositoryUrl = "https://github.com/oss-review-toolkit/ort.git" |
| 55 | + val configs = mapOf( |
| 56 | + VcsType.GIT.toString() to PluginConfig( |
| 57 | + options = mapOf("updateNestedSubmodules" to false.toString()) |
| 58 | + ) |
| 59 | + ) |
| 60 | + |
| 61 | + val vcsWithDefaultConfiguration = VersionControlSystem.forUrl(repositoryUrl) |
| 62 | + val vcsWithConfigs = VersionControlSystem.forUrl(repositoryUrl, configs) |
| 63 | + val vcsWithConfigsFromCache = VersionControlSystem.forUrl(repositoryUrl, configs) |
| 64 | + |
| 65 | + vcsWithDefaultConfiguration shouldNot beNull() |
| 66 | + vcsWithConfigs shouldNot beNull() |
| 67 | + |
| 68 | + vcsWithDefaultConfiguration shouldNotBe vcsWithConfigs |
| 69 | + vcsWithConfigsFromCache shouldBe vcsWithConfigs |
| 70 | + } |
| 71 | + } |
| 72 | +}) |
0 commit comments