@@ -584,6 +584,63 @@ func TestGetSettingsRedaction(t *testing.T) {
584584 _ = db
585585}
586586
587+ func TestS3QuotaSettingsConfigAndStats (t * testing.T ) {
588+ h , _ , db := newTestHandler (t )
589+ ctx := context .Background ()
590+
591+ patchRec := serve (t , h , http .MethodPatch , "/settings" , []byte (`{"s3Enabled":true,"s3QuotaGb":9}` ))
592+ if patchRec .Code != http .StatusOK {
593+ t .Fatalf ("patch status = %d, body = %s" , patchRec .Code , patchRec .Body .String ())
594+ }
595+ var settingsResp map [string ]any
596+ if err := json .Unmarshal (patchRec .Body .Bytes (), & settingsResp ); err != nil {
597+ t .Fatalf ("decode settings: %v" , err )
598+ }
599+ if settingsResp ["s3QuotaGb" ] != float64 (9 ) {
600+ t .Fatalf ("settings s3QuotaGb = %v" , settingsResp ["s3QuotaGb" ])
601+ }
602+
603+ rec := storage.TorrentRecord {
604+ ID : "S3API" ,
605+ InfoHash : "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ,
606+ Status : "downloaded" ,
607+ AddedAt : time .Now ().UTC (),
608+ Files : []storage.TorrentFileRecord {
609+ {ID : 1 , TorrentID : "S3API" , Path : "/remote.mkv" , Bytes : 2048 , Selected : true , ObjectKey : "remote/movie.mkv" , RemoteStored : true },
610+ },
611+ }
612+ if err := db .CreateTorrent (ctx , rec ); err != nil {
613+ t .Fatalf ("create torrent: %v" , err )
614+ }
615+
616+ configRec := serve (t , h , http .MethodGet , "/config" , nil )
617+ if configRec .Code != http .StatusOK {
618+ t .Fatalf ("config status = %d" , configRec .Code )
619+ }
620+ var configResp map [string ]any
621+ if err := json .Unmarshal (configRec .Body .Bytes (), & configResp ); err != nil {
622+ t .Fatalf ("decode config: %v" , err )
623+ }
624+ if configResp ["s3QuotaGb" ] != float64 (9 ) || configResp ["s3Enabled" ] != true {
625+ t .Fatalf ("config S3 fields = %+v" , configResp )
626+ }
627+
628+ statsRec := serve (t , h , http .MethodGet , "/stats" , nil )
629+ if statsRec .Code != http .StatusOK {
630+ t .Fatalf ("stats status = %d" , statsRec .Code )
631+ }
632+ var statsResp map [string ]any
633+ if err := json .Unmarshal (statsRec .Body .Bytes (), & statsResp ); err != nil {
634+ t .Fatalf ("decode stats: %v" , err )
635+ }
636+ if statsResp ["s3Used" ] != float64 (2048 ) || statsResp ["s3ObjectCount" ] != float64 (1 ) {
637+ t .Fatalf ("stats S3 usage = %+v" , statsResp )
638+ }
639+ if statsResp ["s3QuotaGb" ] != float64 (9 ) || statsResp ["s3Quota" ] != float64 (9 * 1024 * 1024 * 1024 ) {
640+ t .Fatalf ("stats S3 quota = %+v" , statsResp )
641+ }
642+ }
643+
587644func TestDeleteSelfRejected (t * testing.T ) {
588645 cfg := testConfig ()
589646 cfg .MultiUserEnabled = true
0 commit comments