feat: add tray control, priority restoration and session logging
This commit is contained in:
1 parent
4f8f6218ad
commit
4880aa46dc
25 files changed
+3072
-676
No files matched your search
@@ -0,0 +1,73 @@
|
||||
//go:build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func TestLogRotationBoundedUTF8AndRestart(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "test.log")
|
||||
w, e := openRotatingLog(path, 256)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for i := 0; i < 8; i++ {
|
||||
if e = w.Write(strings.Repeat("АБ", 40) + "\n"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
if e = w.Write(strings.Repeat("Ж", 600)); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = w.Close(); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, p := range []string{path, path + ".1"} {
|
||||
data, e := os.ReadFile(p)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if len(data) > 256 {
|
||||
t.Fatalf("unbounded log: %d bytes", len(data))
|
||||
}
|
||||
if !utf8.Valid(data) {
|
||||
t.Fatal("split a UTF-8 character")
|
||||
}
|
||||
}
|
||||
w, e = openRotatingLog(path, 256)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = w.Write("LAST\n"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
w.Close()
|
||||
data, e := os.ReadFile(path)
|
||||
if e != nil || !strings.HasSuffix(string(data), "LAST\n") {
|
||||
t.Fatal("restart failed")
|
||||
}
|
||||
entries, _ := os.ReadDir(filepath.Dir(path))
|
||||
if len(entries) != 1 {
|
||||
t.Fatalf("unexpected files: %d", len(entries))
|
||||
}
|
||||
}
|
||||
func TestLogRejectsDirectoryAndClosedWriter(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
if w, e := openRotatingLog(dir, 256); e == nil {
|
||||
w.Close()
|
||||
t.Fatal("accepted a directory")
|
||||
}
|
||||
w, e := openRotatingLog(filepath.Join(dir, "x.log"), 256)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
w.Close()
|
||||
if e = w.Write("x"); e == nil {
|
||||
t.Fatal("silenced write after close")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user