Share typed publication completion evidence
This commit is contained in:
39
internal/artifacts/publication_metadata_test.go
Normal file
39
internal/artifacts/publication_metadata_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package artifacts
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPublicationMetadataRoundTrip(t *testing.T) {
|
||||
metadata := PublicationCompletionMetadata(PublicationIdentity{RunID: "run", CommitKey: "commit", PointerKey: "pointer"})
|
||||
metadata[PublicationOutcomesKey] = []map[string]any{
|
||||
PublicationOutcomeMetadata(PublicationOutcome{Source: "one", Status: PublicationPublished, Destination: "a", DeclaredKey: "key", OriginRun: "run"}),
|
||||
{"source": "bad", "status": "invalid"},
|
||||
PublicationOutcomeMetadata(PublicationOutcome{Source: "two", Status: PublicationOptionalMissing}),
|
||||
}
|
||||
before := DecodePublicationCompletion(metadata)
|
||||
outcomes := DecodePublicationOutcomes(metadata)
|
||||
if !before.Uploaded.Valid || !before.Uploaded.Value || before.Skipped.Present || !before.RunID.Valid || len(outcomes) != 2 {
|
||||
t.Fatalf("completion = %+v, outcomes = %+v", before, outcomes)
|
||||
}
|
||||
body, err := json.Marshal(metadata)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var decoded map[string]any
|
||||
if err := json.Unmarshal(body, &decoded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := DecodePublicationCompletion(decoded); !reflect.DeepEqual(got, before) {
|
||||
t.Fatalf("completion = %+v, want %+v", got, before)
|
||||
}
|
||||
if got := DecodePublicationOutcomes(decoded); !reflect.DeepEqual(got, outcomes) {
|
||||
t.Fatalf("outcomes = %+v, want %+v", got, outcomes)
|
||||
}
|
||||
decoded[PublicationSkippedKey] = "false"
|
||||
if field := DecodePublicationCompletion(decoded).Skipped; !field.Present || field.Valid {
|
||||
t.Fatalf("malformed skipped = %+v", field)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user