Files
Gokapi/internal/storage/processingstatus/pstatusdb/PStatusDb_test.go
T
Marc Bulling d88f649209 Add support for multiple different users, rewrote API, breaking API changes, UI changes
* Require 1.9.6 for upgrade, add function to get userID from request

* Automatically add user when successfully authenticated with headers / oauth, disallow modifing own user permissions

* Dont show user/pw page when using header authentication

* Only display redacted versions of API keys #228, fixed deployment password

* Added animation for deleting API key

* Only create salt once

* Disable elements on upload UI if insufficient permissions

* BREAKING: User field must be email for OAUTH2, added warning in setup when changing database

* BREAKING: Added option to restrict to only registered users

* Fixed crash due to concurrent map iteration

* Replace /uploadComplete with API call, BREAKING API is now in headers

* BREAKING: require true|false instead of only checking for true

* BREAKING API: Renamed apiKeyToModify parameter to targetKey
2025-02-04 09:22:55 +01:00

73 lines
1.8 KiB
Go

package pstatusdb
import (
"github.com/forceu/gokapi/internal/models"
"github.com/forceu/gokapi/internal/test"
"testing"
"time"
)
func TestSetStatus(t *testing.T) {
isGbStarted = true
const id = "testchunk"
status, ok := getStatus(id)
test.IsEqualBool(t, ok, false)
test.IsEmpty(t, status.ChunkId)
Set(models.UploadStatus{
ChunkId: id,
CurrentStatus: 2,
FileId: "testfile",
})
status, ok = getStatus(id)
test.IsEqualBool(t, ok, true)
test.IsEqualString(t, status.ChunkId, id)
test.IsEqualString(t, status.FileId, "testfile")
test.IsEqualInt(t, status.CurrentStatus, 2)
Set(models.UploadStatus{
ChunkId: id,
CurrentStatus: 1,
})
status, ok = getStatus(id)
test.IsEqualBool(t, ok, true)
test.IsEqualString(t, status.ChunkId, id)
test.IsEqualInt(t, status.CurrentStatus, 2)
Set(models.UploadStatus{
ChunkId: id,
CurrentStatus: 3,
FileId: "testfile",
ErrorMessage: "test",
})
status, ok = getStatus(id)
test.IsEqualBool(t, ok, true)
test.IsEqualString(t, status.ChunkId, id)
test.IsEqualInt(t, status.CurrentStatus, 3)
test.IsEqualString(t, status.FileId, "testfile")
test.IsEqualString(t, status.ErrorMessage, "test")
}
func TestGarbageCollection(t *testing.T) {
Set(models.UploadStatus{
ChunkId: "toBeGarbaged",
CurrentStatus: 2,
})
test.IsEqualInt(t, len(GetAll()), 2)
doGarbageCollection(false)
test.IsEqualInt(t, len(GetAll()), 2)
status, ok := statusMap["toBeGarbaged"]
test.IsEqualBool(t, ok, true)
status.Creation = time.Now().Add(-30 * time.Hour).Unix()
statusMap["toBeGarbaged"] = status
test.IsEqualInt(t, len(GetAll()), 2)
doGarbageCollection(false)
test.IsEqualInt(t, len(GetAll()), 1)
}
func getStatus(id string) (models.UploadStatus, bool) {
for _, status := range GetAll() {
if status.ChunkId == id {
return status, true
}
}
return models.UploadStatus{}, false
}