Add Go consent tool and Gitea build workflow
This commit is contained in:
44
VRWT_Tool/VRC_OSC/internal/consenttool/tool_test.go
Normal file
44
VRWT_Tool/VRC_OSC/internal/consenttool/tool_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package consenttool
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCollectConsentedNames(t *testing.T) {
|
||||
rows := []map[string]string{
|
||||
{"display_name": "Alice", "consent": "true"},
|
||||
{"display_name": "Bob", "consent": "false"},
|
||||
{"display_name": "Alice", "consent": "yes"},
|
||||
}
|
||||
|
||||
names := collectConsentedNames(rows, ConsentConfig{})
|
||||
if len(names) != 1 || names[0] != "Alice" {
|
||||
t.Fatalf("unexpected names: %#v", names)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractLog(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
cfg := &Config{
|
||||
Log: LogConfig{
|
||||
InputPath: "input.log",
|
||||
OutputPath: "out.log",
|
||||
IncludeRegex: `ID:[0-9]+`,
|
||||
},
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "input.log"), []byte("x\nID:1 hello\nnope\n"), 0o600); err != nil {
|
||||
t.Fatalf("WriteFile: %v", err)
|
||||
}
|
||||
if err := extractLog(cfg, dir); err != nil {
|
||||
t.Fatalf("extractLog: %v", err)
|
||||
}
|
||||
out, err := os.ReadFile(filepath.Join(dir, "out.log"))
|
||||
if err != nil {
|
||||
t.Fatalf("ReadFile: %v", err)
|
||||
}
|
||||
if string(out) != "ID:1 hello\n" {
|
||||
t.Fatalf("unexpected output: %q", string(out))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user