- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add initial retention policy #121
Merged
+184
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading status checks…
Add initial retention policy
- v0.6.1
- v0.6.0
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- nightly-20250214
- nightly-20250211
- nightly-20250210
- nightly-20250209
- nightly-20250126
- nightly-20250124
- nightly-20250123
- nightly-20250122
- nightly-20250121
- nightly-20250119
- nightly-20250115
- nightly-20250113
- nightly-20250109
- nightly-20250105
- nightly-20250103
- nightly-20241223
- nightly-20241221
- nightly-20241220
- nightly-20241218
- nightly-25
commit 365730aade76a492367a0a302bbe418b8e49f958
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package datastore | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/tphakala/birdnet-go/internal/conf" | ||
"github.com/tphakala/birdnet-go/internal/logger" | ||
) | ||
|
||
func createDatabase(t testing.TB, settings *conf.Settings) Interface { | ||
tempDir := t.TempDir() | ||
settings.Output.SQLite.Enabled = true | ||
settings.Output.SQLite.Path = tempDir + "/test.db" | ||
|
||
dataStore := New(settings) | ||
|
||
// Open a connection to the database and handle possible errors. | ||
if err := dataStore.Open(); err != nil { | ||
logger.Error("main", "Failed to open database: %v", err) | ||
} else { | ||
t.Cleanup(func() { dataStore.Close() }) | ||
} | ||
|
||
return dataStore | ||
} | ||
|
||
func TestGetClipsQualifyingForRemoval(t *testing.T) { | ||
|
||
settings := &conf.Settings{} | ||
|
||
dataStore := createDatabase(t, settings) | ||
|
||
// One Cool bird should be removed since there is one too many | ||
// No Amazing bird should be removed since there is only one | ||
// While there are two Wonderful birds, only one of them are old enough, but too few to be removed | ||
// While there are two Magnificent birds, only one of them have a clip, meaning that the remaining one should be kept | ||
dataStore.Save(&Note{ | ||
ClipName: "test.wav", | ||
ScientificName: "Cool bird", | ||
BeginTime: time.Now().Add(-2 * time.Hour), | ||
}, []Results{}) | ||
dataStore.Save(&Note{ | ||
ClipName: "test2.wav", | ||
ScientificName: "Amazing bird", | ||
BeginTime: time.Now().Add(-2 * time.Hour), | ||
}, []Results{}) | ||
dataStore.Save(&Note{ | ||
ClipName: "test3.wav", | ||
ScientificName: "Cool bird", | ||
BeginTime: time.Now().Add(-2 * time.Hour), | ||
}, []Results{}) | ||
dataStore.Save(&Note{ | ||
ClipName: "test4.wav", | ||
ScientificName: "Wonderful bird", | ||
BeginTime: time.Now().Add(-2 * time.Hour), | ||
}, []Results{}) | ||
dataStore.Save(&Note{ | ||
ClipName: "test5.wav", | ||
ScientificName: "Magnificent bird", | ||
BeginTime: time.Now().Add(-2 * time.Hour), | ||
}, []Results{}) | ||
dataStore.Save(&Note{ | ||
ClipName: "", | ||
ScientificName: "Magnificent bird", | ||
BeginTime: time.Now(), | ||
}, []Results{}) | ||
dataStore.Save(&Note{ | ||
ClipName: "test7.wav", | ||
ScientificName: "Wonderful bird", | ||
BeginTime: time.Now(), | ||
}, []Results{}) | ||
|
||
minHours := 1 | ||
minClips := 1 | ||
|
||
clipsForRemoval, err := dataStore.GetClipsQualifyingForRemoval(minHours, minClips) | ||
|
||
if err != nil { | ||
t.Errorf("Expected no error, got %v", err) | ||
} | ||
if len(clipsForRemoval) != 1 { | ||
t.Errorf("Expected one entry in clipsForRemoval, got %d", len(clipsForRemoval)) | ||
} | ||
if clipsForRemoval[0].ScientificName != "Cool bird" { | ||
t.Errorf("Expected ScientificName to be 'Cool bird', got '%s'", clipsForRemoval[0].ScientificName) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of
dataStore.Save
is not checked. Consider handling this to avoid uncaught errors during tests.Committable suggestion