Skip to content

Commit 57864b5

Browse files
committed
refactor(tests): Extract the repository and artifact provenances
Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent aa6b53d commit 57864b5

File tree

1 file changed

+28
-73
lines changed

1 file changed

+28
-73
lines changed

model/src/test/kotlin/config/PackageConfigurationTest.kt

Lines changed: 28 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ import org.ossreviewtoolkit.model.SourceCodeOrigin
3030
import org.ossreviewtoolkit.model.VcsInfo
3131
import org.ossreviewtoolkit.model.VcsType
3232

33+
private val ARTIFACT_PROVENANCE = ArtifactProvenance(
34+
sourceArtifact = RemoteArtifact.EMPTY.copy(
35+
url = "https://host/path/file.zip"
36+
)
37+
)
38+
39+
private val REPOSITORY_PROVENANCE = RepositoryProvenance(
40+
vcsInfo = VcsInfo(
41+
type = VcsType.GIT,
42+
url = "ssh://git@host/repo.git",
43+
revision = ""
44+
),
45+
resolvedRevision = "12345678"
46+
)
47+
3348
private fun vcsPackageConfig(name: String, revision: String, url: String) =
3449
PackageConfiguration(
3550
id = Identifier.EMPTY.copy(name = name),
@@ -53,14 +68,7 @@ class PackageConfigurationTest : WordSpec({
5368

5469
config.matches(
5570
config.id,
56-
RepositoryProvenance(
57-
vcsInfo = VcsInfo(
58-
type = VcsType.GIT,
59-
url = "ssh://git@host/repo.git",
60-
revision = ""
61-
),
62-
resolvedRevision = "12345678"
63-
)
71+
REPOSITORY_PROVENANCE
6472
) shouldBe true
6573
}
6674

@@ -69,14 +77,7 @@ class PackageConfigurationTest : WordSpec({
6977

7078
config.matches(
7179
Identifier.EMPTY.copy(name = "some-other-name"),
72-
RepositoryProvenance(
73-
vcsInfo = VcsInfo(
74-
type = VcsType.GIT,
75-
url = "ssh://git@host/repo.git",
76-
revision = ""
77-
),
78-
resolvedRevision = "12345678"
79-
)
80+
REPOSITORY_PROVENANCE
8081
) shouldBe false
8182
}
8283

@@ -85,30 +86,16 @@ class PackageConfigurationTest : WordSpec({
8586

8687
config.matches(
8788
config.id,
88-
RepositoryProvenance(
89-
vcsInfo = VcsInfo(
90-
type = VcsType.GIT,
91-
url = "ssh://host/repo.git",
92-
revision = ""
93-
),
94-
resolvedRevision = "12345678"
95-
)
96-
) shouldBe true
89+
REPOSITORY_PROVENANCE.copy(vcsInfo = REPOSITORY_PROVENANCE.vcsInfo.copy(url = "ssh://host/repo.git"))
90+
)
9791
}
9892

9993
"return false if only resolved revision is not equal to the matcher's revision" {
10094
val config = vcsPackageConfig(name = "some-name", revision = "12345678", url = "ssh://git@host/repo.git")
10195

10296
config.matches(
10397
config.id,
104-
RepositoryProvenance(
105-
vcsInfo = VcsInfo(
106-
type = VcsType.GIT,
107-
url = "ssh://git@host/repo.git",
108-
revision = "12345678"
109-
),
110-
resolvedRevision = "12"
111-
)
98+
REPOSITORY_PROVENANCE.copy(resolvedRevision = "12")
11299
) shouldBe false
113100
}
114101

@@ -117,11 +104,7 @@ class PackageConfigurationTest : WordSpec({
117104

118105
config.matches(
119106
config.id,
120-
ArtifactProvenance(
121-
sourceArtifact = RemoteArtifact.EMPTY.copy(
122-
url = "https://host/path/file.zip"
123-
)
124-
)
107+
ARTIFACT_PROVENANCE
125108
) shouldBe true
126109
}
127110

@@ -130,8 +113,8 @@ class PackageConfigurationTest : WordSpec({
130113

131114
config.matches(
132115
config.id,
133-
ArtifactProvenance(
134-
sourceArtifact = RemoteArtifact.EMPTY.copy(
116+
ARTIFACT_PROVENANCE.copy(
117+
sourceArtifact = ARTIFACT_PROVENANCE.sourceArtifact.copy(
135118
url = "https://host/path/some-other-file.zip"
136119
)
137120
)
@@ -146,14 +129,7 @@ class PackageConfigurationTest : WordSpec({
146129

147130
config.matches(
148131
config.id.copy(type = "gradle"),
149-
RepositoryProvenance(
150-
vcsInfo = VcsInfo(
151-
type = VcsType.GIT,
152-
url = "ssh://git@host/repo.git",
153-
revision = ""
154-
),
155-
resolvedRevision = "12345678"
156-
)
132+
REPOSITORY_PROVENANCE
157133
) shouldBe true
158134
}
159135

@@ -166,14 +142,7 @@ class PackageConfigurationTest : WordSpec({
166142

167143
config.matches(
168144
config.id,
169-
RepositoryProvenance(
170-
vcsInfo = VcsInfo(
171-
type = VcsType.GIT,
172-
url = "ssh://git@host/repo.git",
173-
revision = ""
174-
),
175-
resolvedRevision = "12345678"
176-
)
145+
REPOSITORY_PROVENANCE
177146
) shouldBe true
178147
}
179148

@@ -186,11 +155,7 @@ class PackageConfigurationTest : WordSpec({
186155

187156
config.matches(
188157
config.id,
189-
ArtifactProvenance(
190-
sourceArtifact = RemoteArtifact.EMPTY.copy(
191-
url = "https://host/path/some-other-file.zip"
192-
)
193-
)
158+
ARTIFACT_PROVENANCE
194159
) shouldBe true
195160
}
196161

@@ -203,14 +168,7 @@ class PackageConfigurationTest : WordSpec({
203168

204169
config.matches(
205170
config.id,
206-
RepositoryProvenance(
207-
vcsInfo = VcsInfo(
208-
type = VcsType.GIT,
209-
url = "ssh://git@host/repo.git",
210-
revision = ""
211-
),
212-
resolvedRevision = "12345678"
213-
)
171+
REPOSITORY_PROVENANCE
214172
) shouldBe false
215173
}
216174

@@ -219,10 +177,7 @@ class PackageConfigurationTest : WordSpec({
219177

220178
config.matches(
221179
config.id,
222-
RepositoryProvenance(
223-
vcsInfo = VcsInfo.EMPTY,
224-
resolvedRevision = "12345678"
225-
)
180+
REPOSITORY_PROVENANCE
226181
) shouldBe true
227182
}
228183
}

0 commit comments

Comments
 (0)