Support TXT uploads and extend XigmaNAS event parsing

This commit is contained in:
2026-02-04 22:25:43 +03:00
parent ae588ae75a
commit 92134a6cc1
6 changed files with 296 additions and 5 deletions

View File

@@ -0,0 +1,48 @@
package parser
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestExtractArchiveFromReaderTXT(t *testing.T) {
content := "loader_brand=\"XigmaNAS\"\nSystem uptime:\n"
files, err := ExtractArchiveFromReader(strings.NewReader(content), "xigmanas.txt")
if err != nil {
t.Fatalf("extract txt from reader: %v", err)
}
if len(files) != 1 {
t.Fatalf("expected 1 file, got %d", len(files))
}
if files[0].Path != "xigmanas.txt" {
t.Fatalf("expected filename xigmanas.txt, got %q", files[0].Path)
}
if string(files[0].Content) != content {
t.Fatalf("content mismatch")
}
}
func TestExtractArchiveTXT(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "sample.txt")
want := "plain text log"
if err := os.WriteFile(path, []byte(want), 0o600); err != nil {
t.Fatalf("write sample txt: %v", err)
}
files, err := ExtractArchive(path)
if err != nil {
t.Fatalf("extract txt file: %v", err)
}
if len(files) != 1 {
t.Fatalf("expected 1 file, got %d", len(files))
}
if files[0].Path != "sample.txt" {
t.Fatalf("expected sample.txt, got %q", files[0].Path)
}
if string(files[0].Content) != want {
t.Fatalf("content mismatch")
}
}