Skip to content

Commit e81e340

Browse files
committed
test(downloader): Split forUrl() to funTest
These actually depend on the `git` executable and thus are not pure (unit) tests. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent b939a1f commit e81e340

File tree

2 files changed

+72
-44
lines changed

2 files changed

+72
-44
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
})

downloader/src/test/kotlin/VersionControlSystemTest.kt

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@
2020
package org.ossreviewtoolkit.downloader
2121

2222
import io.kotest.core.spec.style.WordSpec
23-
import io.kotest.matchers.nulls.beNull
24-
import io.kotest.matchers.nulls.shouldNotBeNull
2523
import io.kotest.matchers.result.shouldBeSuccess
26-
import io.kotest.matchers.should
2724
import io.kotest.matchers.shouldBe
28-
import io.kotest.matchers.shouldNot
29-
import io.kotest.matchers.shouldNotBe
3025

3126
import io.mockk.every
3227
import io.mockk.mockk
@@ -123,43 +118,4 @@ class VersionControlSystemTest : WordSpec({
123118
)
124119
}
125120
}
126-
127-
"forUrl()" should {
128-
"return null for an unsupported repository URL" {
129-
val repositoryUrl = "https://example.com"
130-
131-
val vcs = VersionControlSystem.forUrl(repositoryUrl)
132-
133-
vcs should beNull()
134-
}
135-
136-
"return a VCS instance that can handle a Git repository URL" {
137-
val repositoryUrl = "https://github.com/oss-review-toolkit/ort.git"
138-
139-
val vcs = VersionControlSystem.forUrl(repositoryUrl)
140-
141-
vcs shouldNotBeNull {
142-
type shouldBe VcsType.GIT
143-
}
144-
}
145-
146-
"return the VCS instance with the correct configuration from cache" {
147-
val repositoryUrl = "https://github.com/oss-review-toolkit/ort.git"
148-
val configs = mapOf(
149-
VcsType.GIT.toString() to PluginConfig(
150-
options = mapOf("updateNestedSubmodules" to false.toString())
151-
)
152-
)
153-
154-
val vcsWithDefaultConfiguration = VersionControlSystem.forUrl(repositoryUrl)
155-
val vcsWithConfigs = VersionControlSystem.forUrl(repositoryUrl, configs)
156-
val vcsWithConfigsFromCache = VersionControlSystem.forUrl(repositoryUrl, configs)
157-
158-
vcsWithDefaultConfiguration shouldNot beNull()
159-
vcsWithConfigs shouldNot beNull()
160-
161-
vcsWithDefaultConfiguration shouldNotBe vcsWithConfigs
162-
vcsWithConfigsFromCache shouldBe vcsWithConfigs
163-
}
164-
}
165121
})

0 commit comments

Comments
 (0)