45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
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))
|
|
}
|
|
}
|