Add run manifest and logical output file contracts
This commit is contained in:
@@ -230,11 +230,44 @@ func TestFakeMergeNormalizeAndOutputContracts(t *testing.T) {
|
||||
if encoder.Key() != "generic-output" {
|
||||
t.Fatalf("OutputEncoder.Key() = %q, want generic-output", encoder.Key())
|
||||
}
|
||||
if encoded.ContentType != "application/json" {
|
||||
t.Fatalf("ContentType = %q, want application/json", encoded.ContentType)
|
||||
if len(encoded.Files) != 1 {
|
||||
t.Fatalf("len(Files) = %d, want 1", len(encoded.Files))
|
||||
}
|
||||
if string(encoded.Bytes) != `{"run_id":"run-1","approved_count":1}` {
|
||||
t.Fatalf("Bytes = %s, want encoded output", encoded.Bytes)
|
||||
if encoded.Files[0].ContentType != "application/json" {
|
||||
t.Fatalf("ContentType = %q, want application/json", encoded.Files[0].ContentType)
|
||||
}
|
||||
if string(encoded.Files[0].Bytes) != `{"run_id":"run-1","approved_count":1}` {
|
||||
t.Fatalf("Bytes = %s, want encoded output", encoded.Files[0].Bytes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputFileJSONShapeOmitsBytes(t *testing.T) {
|
||||
file := OutputFile{
|
||||
Name: "artifacts/events.json",
|
||||
ContentType: "application/json",
|
||||
Bytes: []byte(`{"ignored":true}`),
|
||||
}
|
||||
|
||||
encoded, err := json.Marshal(file)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error = %v, want nil", err)
|
||||
}
|
||||
|
||||
var got map[string]any
|
||||
if err := json.Unmarshal(encoded, &got); err != nil {
|
||||
t.Fatalf("json.Unmarshal() error = %v, want nil", err)
|
||||
}
|
||||
if got["name"] != "artifacts/events.json" {
|
||||
t.Fatalf("name = %#v, want logical file name", got["name"])
|
||||
}
|
||||
if got["content_type"] != "application/json" {
|
||||
t.Fatalf("content_type = %#v, want application/json", got["content_type"])
|
||||
}
|
||||
if _, ok := got["Bytes"]; ok {
|
||||
t.Fatalf("encoded output file leaked Bytes: %s", encoded)
|
||||
}
|
||||
if _, ok := got["bytes"]; ok {
|
||||
t.Fatalf("encoded output file leaked bytes: %s", encoded)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,7 +430,12 @@ func (encoder fakeOutputEncoder) Key() string {
|
||||
|
||||
func (encoder fakeOutputEncoder) Encode(ctx context.Context, req OutputRequest) (OutputResult, error) {
|
||||
return OutputResult{
|
||||
Bytes: []byte(`{"run_id":"` + req.Manifest.RunID + `","approved_count":1}`),
|
||||
ContentType: "application/json",
|
||||
Files: []OutputFile{
|
||||
{
|
||||
Name: "artifacts/generic.json",
|
||||
ContentType: "application/json",
|
||||
Bytes: []byte(`{"run_id":"` + req.Manifest.RunID + `","approved_count":1}`),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user