@@ -762,3 +762,112 @@ func TestConcurrentOperations(t *testing.T) {
762762 t .Error ("ISO corrupted after concurrent operations" )
763763 }
764764}
765+
766+ func TestListISOsWithMissingSize (t * testing.T ) {
767+ db , cleanup := setupTestDB (t )
768+ defer cleanup ()
769+
770+ // Create ISOs with various states
771+ // ISO 1: complete with size_bytes = 0 (should be returned)
772+ iso1 := createTestISO ()
773+ iso1 .ID = "iso-missing-size-1"
774+ iso1 .Name = "missing-size-1"
775+ iso1 .Status = models .StatusComplete
776+ iso1 .SizeBytes = 0
777+ if err := db .CreateISO (iso1 ); err != nil {
778+ t .Fatalf ("Failed to create iso1: %v" , err )
779+ }
780+
781+ // ISO 2: complete with size_bytes > 0 (should NOT be returned)
782+ iso2 := createTestISO ()
783+ iso2 .ID = "iso-has-size"
784+ iso2 .Name = "has-size"
785+ iso2 .Status = models .StatusComplete
786+ iso2 .SizeBytes = 1000000
787+ if err := db .CreateISO (iso2 ); err != nil {
788+ t .Fatalf ("Failed to create iso2: %v" , err )
789+ }
790+
791+ // ISO 3: pending with size_bytes = 0 (should NOT be returned - not complete)
792+ iso3 := createTestISO ()
793+ iso3 .ID = "iso-pending"
794+ iso3 .Name = "pending"
795+ iso3 .Status = models .StatusPending
796+ iso3 .SizeBytes = 0
797+ if err := db .CreateISO (iso3 ); err != nil {
798+ t .Fatalf ("Failed to create iso3: %v" , err )
799+ }
800+
801+ // ISO 4: failed with size_bytes = 0 (should NOT be returned - not complete)
802+ iso4 := createTestISO ()
803+ iso4 .ID = "iso-failed"
804+ iso4 .Name = "failed"
805+ iso4 .Status = models .StatusFailed
806+ iso4 .SizeBytes = 0
807+ if err := db .CreateISO (iso4 ); err != nil {
808+ t .Fatalf ("Failed to create iso4: %v" , err )
809+ }
810+
811+ // ISO 5: complete with size_bytes = 0 (should be returned)
812+ iso5 := createTestISO ()
813+ iso5 .ID = "iso-missing-size-2"
814+ iso5 .Name = "missing-size-2"
815+ iso5 .Status = models .StatusComplete
816+ iso5 .SizeBytes = 0
817+ if err := db .CreateISO (iso5 ); err != nil {
818+ t .Fatalf ("Failed to create iso5: %v" , err )
819+ }
820+
821+ // Test ListISOsWithMissingSize
822+ isos , err := db .ListISOsWithMissingSize ()
823+ if err != nil {
824+ t .Fatalf ("ListISOsWithMissingSize() failed: %v" , err )
825+ }
826+
827+ // Should return exactly 2 ISOs (iso1 and iso5)
828+ if len (isos ) != 2 {
829+ t .Errorf ("Expected 2 ISOs with missing size, got %d" , len (isos ))
830+ }
831+
832+ // Verify the returned ISOs are the correct ones
833+ foundIDs := make (map [string ]bool )
834+ for _ , iso := range isos {
835+ foundIDs [iso .ID ] = true
836+ // All returned ISOs should be complete with size_bytes = 0
837+ if iso .Status != models .StatusComplete {
838+ t .Errorf ("Returned ISO %s has status %s, expected complete" , iso .ID , iso .Status )
839+ }
840+ if iso .SizeBytes != 0 {
841+ t .Errorf ("Returned ISO %s has size_bytes %d, expected 0" , iso .ID , iso .SizeBytes )
842+ }
843+ }
844+
845+ if ! foundIDs ["iso-missing-size-1" ] {
846+ t .Error ("Expected iso-missing-size-1 to be returned" )
847+ }
848+ if ! foundIDs ["iso-missing-size-2" ] {
849+ t .Error ("Expected iso-missing-size-2 to be returned" )
850+ }
851+ }
852+
853+ func TestListISOsWithMissingSize_Empty (t * testing.T ) {
854+ db , cleanup := setupTestDB (t )
855+ defer cleanup ()
856+
857+ // Create only ISOs that should NOT be returned
858+ iso := createTestISO ()
859+ iso .Status = models .StatusComplete
860+ iso .SizeBytes = 500000
861+ if err := db .CreateISO (iso ); err != nil {
862+ t .Fatalf ("Failed to create ISO: %v" , err )
863+ }
864+
865+ isos , err := db .ListISOsWithMissingSize ()
866+ if err != nil {
867+ t .Fatalf ("ListISOsWithMissingSize() failed: %v" , err )
868+ }
869+
870+ if len (isos ) != 0 {
871+ t .Errorf ("Expected 0 ISOs with missing size, got %d" , len (isos ))
872+ }
873+ }
0 commit comments