(t *testing.T)
| 43 | } |
| 44 | |
| 45 | func TestRenderV02(t *testing.T) { |
| 46 | testCases := []struct { |
| 47 | name string |
| 48 | sourcePath string |
| 49 | outputPath string |
| 50 | }{ |
| 51 | { |
| 52 | name: "default with policy violations", |
| 53 | sourcePath: "testdata/attestation.source.json", |
| 54 | outputPath: "testdata/attestation.output.v0.2.json", |
| 55 | }, |
| 56 | { |
| 57 | name: "with multiple types of materials", |
| 58 | sourcePath: "testdata/attestation.source-2.json", |
| 59 | outputPath: "testdata/attestation.output-2.v0.2.json", |
| 60 | }, |
| 61 | { |
| 62 | name: "V2 schema with policy violations", |
| 63 | sourcePath: "testdata/attestation.source.v2.json", |
| 64 | outputPath: "testdata/attestation.output.v2.json", |
| 65 | }, |
| 66 | { |
| 67 | name: "V2 schema with multiple types of materials", |
| 68 | sourcePath: "testdata/attestation.source-2.v2.json", |
| 69 | outputPath: "testdata/attestation.output-2.v2.json", |
| 70 | }, |
| 71 | } |
| 72 | |
| 73 | for _, tc := range testCases { |
| 74 | t.Run(tc.name, func(t *testing.T) { |
| 75 | // Initialize renderer |
| 76 | state := &api.CraftingState{} |
| 77 | stateRaw, err := os.ReadFile(tc.sourcePath) |
| 78 | require.NoError(t, err) |
| 79 | err = protojson.Unmarshal(stateRaw, state) |
| 80 | require.NoError(t, err) |
| 81 | renderer := NewChainloopRendererV02(state.Attestation, "dev", "sha256:59e14f1a9de709cdd0e91c36b33e54fcca95f7dba1dc7169a7f81986e02108e5", nil, nil) |
| 82 | |
| 83 | // Compare result |
| 84 | statement, err := renderer.Statement(context.TODO()) |
| 85 | require.NoError(t, err) |
| 86 | gotRawStatement, err := json.MarshalIndent(statement, "", " ") |
| 87 | require.NoError(t, err) |
| 88 | |
| 89 | // Update test files |
| 90 | if updateGolden { |
| 91 | err := os.WriteFile(filepath.Clean(tc.outputPath), gotRawStatement, 0600) |
| 92 | require.NoError(t, err) |
| 93 | } |
| 94 | |
| 95 | // Load expected resulting output |
| 96 | raw, err := os.ReadFile(tc.outputPath) |
| 97 | require.NoError(t, err) |
| 98 | var want *intoto.Statement |
| 99 | err = json.Unmarshal(raw, &want) |
| 100 | require.NoError(t, err) |
| 101 | wantRaw, err := json.MarshalIndent(want, "", " ") |
| 102 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected