Initial commit: DSH Web Manager
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestQuotaMonitorReportsTransitions(t *testing.T) {
|
||||
a, _ := runtimeTestAPI(t, func(http.ResponseWriter, *http.Request) {})
|
||||
dir := filepath.Join(a.root, "workspaces", "owner", "files")
|
||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "test"), []byte("over"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
state := map[string]bool{}
|
||||
a.checkQuotas(context.Background(), state)
|
||||
a.checkQuotas(context.Background(), state)
|
||||
if _, err := a.s.DB.Exec("UPDATE users SET quota=100 WHERE id='owner'"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.checkQuotas(context.Background(), state)
|
||||
var count int
|
||||
if err := a.s.DB.QueryRow("SELECT count(*) FROM audit WHERE action IN ('quota.exceeded','quota.recovered')").Scan(&count); err != nil || count != 2 {
|
||||
t.Fatalf("transitions=%d error=%v", count, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user