|
19 | 19 |
|
20 | 20 | package org.ossreviewtoolkit.model.config |
21 | 21 |
|
| 22 | +import io.kotest.assertions.throwables.shouldThrow |
22 | 23 | import io.kotest.core.spec.style.WordSpec |
23 | 24 | import io.kotest.matchers.shouldBe |
24 | 25 |
|
25 | 26 | import org.ossreviewtoolkit.model.ArtifactProvenance |
26 | 27 | import org.ossreviewtoolkit.model.Identifier |
27 | 28 | import org.ossreviewtoolkit.model.RemoteArtifact |
28 | 29 | import org.ossreviewtoolkit.model.RepositoryProvenance |
| 30 | +import org.ossreviewtoolkit.model.SourceCodeOrigin |
29 | 31 | import org.ossreviewtoolkit.model.VcsInfo |
30 | 32 | import org.ossreviewtoolkit.model.VcsType |
31 | 33 |
|
@@ -155,5 +157,68 @@ class PackageConfigurationTest : WordSpec({ |
155 | 157 | ) |
156 | 158 | ) shouldBe true |
157 | 159 | } |
| 160 | + |
| 161 | + "return true if vcs source code origin and identifier are equal" { |
| 162 | + val config = |
| 163 | + PackageConfiguration( |
| 164 | + id = Identifier.EMPTY.copy(name = "some-name"), |
| 165 | + sourceCodeOrigin = SourceCodeOrigin.VCS |
| 166 | + ) |
| 167 | + |
| 168 | + config.matches( |
| 169 | + config.id, |
| 170 | + RepositoryProvenance( |
| 171 | + vcsInfo = VcsInfo( |
| 172 | + type = VcsType.GIT, |
| 173 | + url = "ssh://git@host/repo.git", |
| 174 | + revision = "" |
| 175 | + ), |
| 176 | + resolvedRevision = "12345678" |
| 177 | + ) |
| 178 | + ) shouldBe true |
| 179 | + } |
| 180 | + |
| 181 | + "return true if artifact source code origin and identifier are equal" { |
| 182 | + val config = |
| 183 | + PackageConfiguration( |
| 184 | + id = Identifier.EMPTY.copy(name = "some-name"), |
| 185 | + sourceCodeOrigin = SourceCodeOrigin.ARTIFACT |
| 186 | + ) |
| 187 | + |
| 188 | + config.matches( |
| 189 | + config.id, |
| 190 | + ArtifactProvenance( |
| 191 | + sourceArtifact = RemoteArtifact.EMPTY.copy( |
| 192 | + url = "https://host/path/some-other-file.zip" |
| 193 | + ) |
| 194 | + ) |
| 195 | + ) shouldBe true |
| 196 | + } |
| 197 | + |
| 198 | + "return false if only source code origin is not equal" { |
| 199 | + val config = |
| 200 | + PackageConfiguration( |
| 201 | + id = Identifier.EMPTY.copy(name = "some-name"), |
| 202 | + sourceCodeOrigin = SourceCodeOrigin.ARTIFACT |
| 203 | + ) |
| 204 | + |
| 205 | + config.matches( |
| 206 | + config.id, |
| 207 | + RepositoryProvenance( |
| 208 | + vcsInfo = VcsInfo( |
| 209 | + type = VcsType.GIT, |
| 210 | + url = "ssh://git@host/repo.git", |
| 211 | + revision = "" |
| 212 | + ), |
| 213 | + resolvedRevision = "12345678" |
| 214 | + ) |
| 215 | + ) shouldBe false |
| 216 | + } |
| 217 | + |
| 218 | + "fail if the package configuration has only an identifier" { |
| 219 | + shouldThrow<IllegalArgumentException> { |
| 220 | + PackageConfiguration(id = Identifier.EMPTY.copy(name = "some-name")) |
| 221 | + } |
| 222 | + } |
158 | 223 | } |
159 | 224 | }) |
0 commit comments