-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add demo orphan cleanup. Run demo delete call in addition to assets b…
…ecause FK doesnt cascade for some reason
- Loading branch information
1 parent
7a22a08
commit 7c5d3d0
Showing
9 changed files
with
160 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package test_test | ||
|
||
import ( | ||
"context" | ||
"crypto/rand" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/leighmacdonald/gbans/internal/demo" | ||
"github.com/leighmacdonald/gbans/internal/domain" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDemosCleanup(t *testing.T) { | ||
ctx := context.Background() | ||
fetcher := demo.NewFetcher(tempDB, configUC, serversUC, assetUC, demoUC) | ||
go demoUC.Start(ctx) | ||
|
||
for demoNum := range 10 { | ||
content := make([]byte, 100000) | ||
_, err := rand.Read(content) | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, fetcher.OnDemoReceived(ctx, demo.UploadedDemo{ | ||
Name: fmt.Sprintf("2023111%d-063943-koth_harvest_final.dem", demoNum), | ||
Server: testServer, | ||
Content: content, | ||
})) | ||
} | ||
|
||
conf := configUC.Config() | ||
conf.Demo.DemoCleanupEnabled = true | ||
conf.Demo.DemoCleanupStrategy = domain.DemoStrategyCount | ||
conf.Demo.DemoCountLimit = 5 | ||
|
||
require.NoError(t, configUC.Write(ctx, conf)) | ||
|
||
demoUC.TriggerCleanup() | ||
|
||
allDemos, err := demoUC.GetDemos(ctx) | ||
require.NoError(t, err) | ||
require.Len(t, len(allDemos), 5) | ||
} |
Oops, something went wrong.