-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
50 lines (42 loc) · 1.08 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"os"
"testing"
)
func TestLoadConfig(t *testing.T) {
// Create a temporary file with test data
file, err := os.CreateTemp("", "test-config")
if err != nil {
t.Fatalf("Could not create temp file: %v", err)
}
defer os.Remove(file.Name())
_, err = file.WriteString("foo:bar\nhello:world\n")
if err != nil {
t.Fatalf("Could not write to temp file: %v", err)
}
file.Close()
// Load the config
masks := loadConfig(file.Name())
// Verify the config
if masks["foo"] != "bar" || masks["hello"] != "world" {
t.Errorf("Unexpected masks: %v", masks)
}
}
func TestMaskLine(t *testing.T) {
masks := map[string]string{
"foo": "bar",
"hello": "world",
}
// Test case 1
line := "foo and foo and hello"
expected := "bar and bar and world"
if result := maskLine(line, masks); result != expected {
t.Errorf("Expected '%s', got '%s'", expected, result)
}
// Test case 2
line = "nothing to replace here"
expected = "nothing to replace here"
if result := maskLine(line, masks); result != expected {
t.Errorf("Expected '%s', got '%s'", expected, result)
}
}