Skip to content

Commit 332a496

Browse files
jnd-auoz
authored andcommitted
config_test_keys_dup.toml
1 parent 79eb5ce commit 332a496

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

config_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,48 @@
1717
package main
1818

1919
import (
20+
"os"
2021
"strings"
2122
"testing"
2223
"time"
2324
)
2425

26+
func TestConfigKeysDuplicated(t *testing.T) {
27+
tomlPath := "./config_test_keys_dup.toml"
28+
_, err := LoadConfig(tomlPath, nil)
29+
if err == nil {
30+
t.Errorf("Expected error while reading %s, but didn’t get one", tomlPath)
31+
}
32+
33+
expectedError := "Key(s) mapped multiple times in config: q"
34+
if !strings.Contains(err.Error(), expectedError) {
35+
t.Errorf("Expected specific error while reading %s, but get a different one: %v", tomlPath, err)
36+
}
37+
}
38+
39+
func TestLoadConfig(t *testing.T) {
40+
oldTzList, tzListWasSet := os.LookupEnv("TZ_LIST")
41+
os.Unsetenv("TZ_LIST")
42+
43+
tomlPath := "./example-conf.toml"
44+
_, err := LoadConfig(tomlPath, nil)
45+
if err != nil {
46+
t.Errorf("Could not read %s: %v", tomlPath, err)
47+
}
48+
49+
if tzListWasSet {
50+
os.Setenv("TZ_LIST", oldTzList)
51+
SetupLogger()
52+
}
53+
}
54+
55+
func TestLoadDefaultConfig(t *testing.T) {
56+
_, err := LoadDefaultConfig(nil)
57+
if err != nil {
58+
t.Fatalf("Could not read default config file: %v", err)
59+
}
60+
}
61+
2562
func TestSetupZone(t *testing.T) {
2663
now := time.Now()
2764

config_test_keys_dup.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[keymaps]
2+
prev_hour = ["q"]
3+
quit = ["q"]

0 commit comments

Comments
 (0)