@@ -27,6 +27,7 @@ import io.kotest.core.spec.style.StringSpec
2727import io.kotest.inspectors.forAll
2828import io.kotest.matchers.collections.beEmpty
2929import io.kotest.matchers.should
30+ import io.kotest.matchers.shouldNot
3031
3132import java.io.File
3233
@@ -138,6 +139,130 @@ class JsonSchemaTest : StringSpec({
138139
139140 errors should beEmpty()
140141 }
142+
143+ " Package configuration with no matchers validates successfully" {
144+ val packageConfigurationSchema = File ("../integrations/schemas/package-configuration-schema.json").toURI()
145+ val schema = schemaV7.getSchema(packageConfigurationSchema)
146+
147+ val configWithNoMatchers = """
148+ id: "Pip::example-package:0.0.1"
149+ """ .trimIndent()
150+
151+ val errors = schema.validate(configWithNoMatchers, InputFormat .YAML )
152+
153+ errors should beEmpty()
154+ }
155+
156+ " Package configuration with only vcs validates successfully" {
157+ val packageConfigurationSchema = File ("../integrations/schemas/package-configuration-schema.json").toURI()
158+ val schema = schemaV7.getSchema(packageConfigurationSchema)
159+
160+ val configWithVcs = """
161+ id: "Pip::example-package:0.0.1"
162+ vcs:
163+ type: "Git"
164+ url: "https://github.com/example/repo.git"
165+ """ .trimIndent()
166+
167+ val errors = schema.validate(configWithVcs, InputFormat .YAML )
168+
169+ errors should beEmpty()
170+ }
171+
172+ " Package configuration with only source_artifact_url validates successfully" {
173+ val packageConfigurationSchema = File ("../integrations/schemas/package-configuration-schema.json").toURI()
174+ val schema = schemaV7.getSchema(packageConfigurationSchema)
175+
176+ val configWithSourceArtifact = """
177+ id: "Pip::example-package:0.0.1"
178+ source_artifact_url: "https://example.com/package.tar.gz"
179+ """ .trimIndent()
180+
181+ val errors = schema.validate(configWithSourceArtifact, InputFormat .YAML )
182+
183+ errors should beEmpty()
184+ }
185+
186+ " Package configuration with only source_code_origin validates successfully" {
187+ val packageConfigurationSchema = File ("../integrations/schemas/package-configuration-schema.json").toURI()
188+ val schema = schemaV7.getSchema(packageConfigurationSchema)
189+
190+ val configWithSourceCodeOrigin = """
191+ id: "Pip::example-package:0.0.1"
192+ source_code_origin: "VCS"
193+ """ .trimIndent()
194+
195+ val errors = schema.validate(configWithSourceCodeOrigin, InputFormat .YAML )
196+
197+ errors should beEmpty()
198+ }
199+
200+ " Package configuration with vcs and source_artifact_url fails validation" {
201+ val packageConfigurationSchema = File ("../integrations/schemas/package-configuration-schema.json").toURI()
202+ val schema = schemaV7.getSchema(packageConfigurationSchema)
203+
204+ val configWithVcsAndSourceArtifact = """
205+ id: "Pip::example-package:0.0.1"
206+ vcs:
207+ type: "Git"
208+ url: "https://github.com/example/repo.git"
209+ source_artifact_url: "https://example.com/package.tar.gz"
210+ """ .trimIndent()
211+
212+ val errors = schema.validate(configWithVcsAndSourceArtifact, InputFormat .YAML )
213+
214+ errors shouldNot beEmpty()
215+ }
216+
217+ " Package configuration with vcs and source_code_origin fails validation" {
218+ val packageConfigurationSchema = File ("../integrations/schemas/package-configuration-schema.json").toURI()
219+ val schema = schemaV7.getSchema(packageConfigurationSchema)
220+
221+ val configWithVcsAndSourceCodeOrigin = """
222+ id: "Pip::example-package:0.0.1"
223+ vcs:
224+ type: "Git"
225+ url: "https://github.com/example/repo.git"
226+ source_code_origin: "VCS"
227+ """ .trimIndent()
228+
229+ val errors = schema.validate(configWithVcsAndSourceCodeOrigin, InputFormat .YAML )
230+
231+ errors shouldNot beEmpty()
232+ }
233+
234+ " Package configuration with source_artifact_url and source_code_origin fails validation" {
235+ val packageConfigurationSchema = File ("../integrations/schemas/package-configuration-schema.json").toURI()
236+ val schema = schemaV7.getSchema(packageConfigurationSchema)
237+
238+ val configWithSourceArtifactAndSourceCodeOrigin = """
239+ id: "Pip::example-package:0.0.1"
240+ source_artifact_url: "https://example.com/package.tar.gz"
241+ source_code_origin: "ARTIFACT"
242+ """ .trimIndent()
243+
244+ val errors = schema.validate(configWithSourceArtifactAndSourceCodeOrigin, InputFormat .YAML )
245+
246+ errors shouldNot beEmpty()
247+ }
248+
249+ " Package configuration with all three matchers fails validation" {
250+ val packageConfigurationSchema = File ("../integrations/schemas/package-configuration-schema.json").toURI()
251+ val schema = schemaV7.getSchema(packageConfigurationSchema)
252+
253+ val configWithAllMatchers = """
254+ id: "Pip::example-package:0.0.1"
255+ vcs:
256+ type: "Git"
257+ url: "https://github.com/example/repo.git"
258+ source_artifact_url: "https://example.com/package.tar.gz"
259+ source_code_origin: "VCS"
260+ """ .trimIndent()
261+
262+ val errors = schema.validate(configWithAllMatchers, InputFormat .YAML )
263+
264+ errors shouldNot beEmpty()
265+ }
141266})
142267
143268private val schemaV7 = JsonSchemaFactory .getInstance(SpecVersion .VersionFlag .V7 )
0 commit comments