Add structured destination comparison details
This commit is contained in:
@@ -97,6 +97,93 @@ func TestCompareOutcomes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompareReportsStructuredDetails(t *testing.T) {
|
||||
source := validManifest(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
status DestinationStatus
|
||||
wantKind ComparisonDetailKind
|
||||
assertions func(t *testing.T, detail ComparisonDetail)
|
||||
}{
|
||||
{
|
||||
name: "pipeline mismatch",
|
||||
status: DestinationStatus{State: withState(t, source, func(s *DistributorState) { s.PipelineID = "other" })},
|
||||
wantKind: ComparisonDetailPipelineIDMismatch,
|
||||
assertions: func(t *testing.T, detail ComparisonDetail) {
|
||||
t.Helper()
|
||||
if detail.DestinationPipelineID != "other" || detail.CurrentPipelineID != "reports" {
|
||||
t.Fatalf("detail = %#v, want pipeline ids", detail)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "destination mismatch",
|
||||
status: DestinationStatus{State: withState(t, source, func(s *DistributorState) { s.DestinationID = "other" })},
|
||||
wantKind: ComparisonDetailDestinationIDMismatch,
|
||||
assertions: func(t *testing.T, detail ComparisonDetail) {
|
||||
t.Helper()
|
||||
if detail.DestinationDestinationID != "other" || detail.CurrentDestinationID != "archive" {
|
||||
t.Fatalf("detail = %#v, want destination ids", detail)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "different source id",
|
||||
status: DestinationStatus{State: withState(t, source, func(s *DistributorState) { s.Source.Manifest.ID = "other.source" })},
|
||||
wantKind: ComparisonDetailDifferentSourceID,
|
||||
assertions: func(t *testing.T, detail ComparisonDetail) {
|
||||
t.Helper()
|
||||
if detail.DestinationSourceID != "other.source" || detail.CurrentSourceID != source.ID {
|
||||
t.Fatalf("detail = %#v, want source ids", detail)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "same created digest conflict",
|
||||
status: DestinationStatus{State: withState(t, source, func(s *DistributorState) {
|
||||
s.Source.Manifest.Files[0].SHA256 = "sha256:3333333333333333333333333333333333333333333333333333333333333333"
|
||||
s.Source.Manifest.Digest = bundle.BundleDigest(s.Source.Manifest.Files)
|
||||
})},
|
||||
wantKind: ComparisonDetailSameCreatedDigestConflict,
|
||||
assertions: func(t *testing.T, detail ComparisonDetail) {
|
||||
t.Helper()
|
||||
if detail.CurrentSourceDigest == "" || detail.DestinationSourceDigest == "" || detail.CurrentSourceDigest == detail.DestinationSourceDigest {
|
||||
t.Fatalf("detail = %#v, want different source digests", detail)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "destination newer",
|
||||
status: DestinationStatus{State: withState(t, source, func(s *DistributorState) {
|
||||
s.Source.Manifest.Created = source.Created.Add(time.Hour)
|
||||
})},
|
||||
wantKind: ComparisonDetailDestinationNewer,
|
||||
},
|
||||
{
|
||||
name: "invalid state",
|
||||
status: DestinationStatus{StateErr: errors.New("invalid json")},
|
||||
wantKind: ComparisonDetailInvalidState,
|
||||
},
|
||||
{
|
||||
name: "unmanaged content",
|
||||
status: DestinationStatus{HasContents: true},
|
||||
wantKind: ComparisonDetailUnmanagedContent,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := Compare(source, "reports", "archive", tt.status)
|
||||
if got.Detail.Kind != tt.wantKind {
|
||||
t.Fatalf("Compare() detail kind = %q, want %q; comparison=%#v", got.Detail.Kind, tt.wantKind, got)
|
||||
}
|
||||
if tt.assertions != nil {
|
||||
tt.assertions(t, got.Detail)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func withState(t *testing.T, source bundle.Manifest, mutate func(*DistributorState)) *DistributorState {
|
||||
t.Helper()
|
||||
stateManifest := source
|
||||
|
||||
Reference in New Issue
Block a user