Skip to content

Commit ce55969

Browse files
xingzhang-suserushk014
authored andcommitted
Github #358: Bug: status distribution does not show correct number according to the registry list
1 parent cdd3214 commit ce55969

File tree

2 files changed

+179
-6
lines changed

2 files changed

+179
-6
lines changed

pkg/sbomscanner/pages/c/_cluster/sbomscanner/RegistriesConfiguration.vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,16 @@ export default {
207207
}
208208
}
209209
});
210-
const top5StatusUpdates = Array.from(registryStatusMap.values()).slice(0, 5);
210+
211+
const statusList = Array.from(registryStatusMap.values());
212+
const top5StatusUpdates = statusList.slice(0, 5);
213+
214+
statusList.forEach((rec) => {
215+
// Summarize the data for Status distribution panel
216+
if (Object.prototype.hasOwnProperty.call(statusSummary, rec[0].statusResult.type.toLowerCase())) {
217+
statusSummary[rec[0].statusResult.type.toLowerCase()]++;
218+
}
219+
});
211220
212221
top5StatusUpdates.forEach((rec) => {
213222
registryStatusList.push({
@@ -219,10 +228,6 @@ export default {
219228
lastTransitionTime: Math.max(new Date(rec[0].lastTransitionTime), new Date(rec[0].completionTime))
220229
});
221230
222-
// Summarize the data for Status distribution panel
223-
if (Object.prototype.hasOwnProperty.call(statusSummary, rec[0].statusResult.type.toLowerCase())) {
224-
statusSummary[rec[0].statusResult.type.toLowerCase()]++;
225-
}
226231
});
227232
// Sort and limit the registryStatusList to 5 most recent updates
228233
registryStatusList.sort((a, b) => new Date(b.lastTransitionTime) - new Date(a.lastTransitionTime)).slice(0, 5);

pkg/sbomscanner/pages/c/_cluster/sbomscanner/__tests__/RegistriesConfiguration.spec.ts

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,4 +512,172 @@ describe('RegistriesOverview.vue', () => {
512512
})
513513
);
514514
});
515-
});
515+
});
516+
517+
describe('getSummaryData → statusSummary aggregation', () => {
518+
it('increments correct counters for known status types', () => {
519+
const wrapper = factory();
520+
521+
const mockJobs = [
522+
// Pending
523+
{
524+
metadata: {
525+
namespace: 'ns', name: 'reg1', annotations: { 'sbomscanner.kubewarden.io/registry': '{}' }
526+
},
527+
spec: { registry: 'r1' },
528+
status: {
529+
conditions: [{
530+
type: 'Pending', status: 'True', lastTransitionTime: new Date().toISOString()
531+
}]
532+
}
533+
},
534+
// Complete
535+
{
536+
metadata: {
537+
namespace: 'ns', name: 'reg2', annotations: { 'sbomscanner.kubewarden.io/registry': '{}' }
538+
},
539+
spec: { registry: 'r2' },
540+
status: {
541+
conditions: [{
542+
type: 'Complete', status: 'True', lastTransitionTime: new Date().toISOString()
543+
}]
544+
}
545+
},
546+
// Failed
547+
{
548+
metadata: {
549+
namespace: 'ns', name: 'reg3', annotations: { 'sbomscanner.kubewarden.io/registry': '{}' }
550+
},
551+
spec: { registry: 'r3' },
552+
status: {
553+
conditions: [{
554+
type: 'Failed', status: 'True', lastTransitionTime: new Date().toISOString()
555+
}]
556+
}
557+
},
558+
// Pending
559+
{
560+
metadata: {
561+
namespace: 'ns', name: 'reg4', annotations: { 'sbomscanner.kubewarden.io/registry': '{}' }
562+
},
563+
spec: { registry: 'r4' },
564+
status: {
565+
conditions: [{
566+
type: 'Pending', status: 'True', lastTransitionTime: new Date().toISOString()
567+
}]
568+
}
569+
},
570+
// Inprogress
571+
{
572+
metadata: {
573+
namespace: 'ns', name: 'reg5', annotations: { 'sbomscanner.kubewarden.io/registry': '{}' }
574+
},
575+
spec: { registry: 'r5' },
576+
status: {
577+
conditions: [{
578+
type: 'Inprogress', status: 'True', lastTransitionTime: new Date().toISOString()
579+
}]
580+
}
581+
},
582+
// scheduled
583+
{
584+
metadata: {
585+
namespace: 'ns', name: 'reg6', annotations: { 'sbomscanner.kubewarden.io/registry': '{}' }
586+
},
587+
spec: { registry: 'r6' },
588+
status: {
589+
conditions: [{
590+
type: 'Scheduled', status: 'True', lastTransitionTime: new Date().toISOString()
591+
}]
592+
}
593+
},
594+
];
595+
596+
const { statusSummary } = wrapper.vm.getSummaryData(mockJobs);
597+
598+
expect(statusSummary.pending).toBe(2);
599+
expect(statusSummary.complete).toBe(1);
600+
expect(statusSummary.failed).toBe(1);
601+
602+
// untouched types remain 0
603+
expect(statusSummary.inprogress).toBe(1);
604+
expect(statusSummary.scheduled).toBe(1);
605+
});
606+
607+
it('ignores status types that are not defined in summary map', () => {
608+
const wrapper = factory();
609+
610+
const mockJobs = [
611+
{
612+
metadata: {
613+
namespace: 'ns', name: 'jX', annotations: { 'sbomscanner.kubewarden.io/registry': '{}' }
614+
},
615+
spec: { registry: 'rX' },
616+
status: {
617+
conditions: [{
618+
type: 'UnknownType', status: 'True', lastTransitionTime: new Date().toISOString()
619+
}]
620+
}
621+
},
622+
];
623+
624+
const { statusSummary } = wrapper.vm.getSummaryData(mockJobs);
625+
626+
// All counters remain at 0
627+
expect(statusSummary.pending).toBe(0);
628+
expect(statusSummary.complete).toBe(0);
629+
expect(statusSummary.failed).toBe(0);
630+
expect(statusSummary.scheduled).toBe(0);
631+
expect(statusSummary.inprogress).toBe(0);
632+
});
633+
634+
it('handles mixture of valid and invalid status types', () => {
635+
const wrapper = factory();
636+
637+
const mockJobs = [
638+
{
639+
metadata: {
640+
namespace: 'ns', name: 'j1', annotations: { 'sbomscanner.kubewarden.io/registry': '{}' }
641+
},
642+
spec: { registry: 'r1' },
643+
status: {
644+
conditions: [{
645+
type: 'Complete', status: 'True', lastTransitionTime: new Date().toISOString()
646+
}]
647+
}
648+
},
649+
{
650+
metadata: {
651+
namespace: 'ns', name: 'j2', annotations: { 'sbomscanner.kubewarden.io/registry': '{}' }
652+
},
653+
spec: { registry: 'r2' },
654+
status: {
655+
conditions: [{
656+
type: 'WhoKnows', status: 'True', lastTransitionTime: new Date().toISOString()
657+
}]
658+
}
659+
},
660+
{
661+
metadata: {
662+
namespace: 'ns', name: 'j3', annotations: { 'sbomscanner.kubewarden.io/registry': '{}' }
663+
},
664+
spec: { registry: 'r3' },
665+
status: {
666+
conditions: [{
667+
type: 'Failed', status: 'True', lastTransitionTime: new Date().toISOString()
668+
}]
669+
}
670+
},
671+
];
672+
673+
const { statusSummary } = wrapper.vm.getSummaryData(mockJobs);
674+
675+
expect(statusSummary.complete).toBe(1);
676+
expect(statusSummary.failed).toBe(1);
677+
678+
// Unknown type does not increment anything
679+
expect(statusSummary.pending).toBe(0);
680+
expect(statusSummary.inprogress).toBe(0);
681+
expect(statusSummary.scheduled).toBe(0);
682+
});
683+
});

0 commit comments

Comments
 (0)