MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / TestParseContractV2

Function TestParseContractV2

app/cli/pkg/action/attestation_init_test.go:258–340  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

256}
257
258func TestParseContractV2(t *testing.T) {
259 testCases := []struct {
260 name string
261 contractFile string
262 format pb.WorkflowContractVersionItem_RawBody_Format
263 expectV2Schema bool
264 expectName string
265 expectError bool
266 }{
267 {
268 name: "valid V2 YAML contract",
269 contractFile: "testdata/contract_v2.yaml",
270 format: pb.WorkflowContractVersionItem_RawBody_FORMAT_YAML,
271 expectV2Schema: true,
272 expectName: "test-contract-v2",
273 },
274 {
275 name: "V1 contract should fail V2 parsing",
276 contractFile: "testdata/contract_v1.yaml",
277 format: pb.WorkflowContractVersionItem_RawBody_FORMAT_YAML,
278 expectV2Schema: false,
279 },
280 {
281 name: "invalid contract data",
282 contractFile: "testdata/invalid_contract.yaml",
283 format: pb.WorkflowContractVersionItem_RawBody_FORMAT_YAML,
284 expectV2Schema: false,
285 },
286 {
287 name: "nil raw contract",
288 contractFile: "",
289 format: pb.WorkflowContractVersionItem_RawBody_FORMAT_YAML,
290 expectV2Schema: false,
291 },
292 }
293
294 for _, tc := range testCases {
295 t.Run(tc.name, func(t *testing.T) {
296 var rawContract *pb.WorkflowContractVersionItem_RawBody
297
298 if tc.contractFile != "" {
299 // Load contract file
300 data, err := os.ReadFile(tc.contractFile)
301 if err != nil {
302 if tc.expectV2Schema {
303 require.NoError(t, err, "Failed to load contract file")
304 }
305 // For non-existent files, test with nil
306 rawContract = nil
307 } else {
308 rawContract = &pb.WorkflowContractVersionItem_RawBody{
309 Body: data,
310 Format: tc.format,
311 }
312 }
313 }
314
315 result := parseContractV2(rawContract)

Callers

nothing calls this directly

Calls 11

parseContractV2Function · 0.85
GetNameMethod · 0.65
GetMetadataMethod · 0.65
GetMaterialsMethod · 0.65
GetAnnotationsMethod · 0.65
RunMethod · 0.45
GetApiVersionMethod · 0.45
GetKindMethod · 0.45
GetSpecMethod · 0.45
GetEnvAllowListMethod · 0.45
GetRunnerMethod · 0.45

Tested by

no test coverage detected