MCPcopy
hub / github.com/nextdns/nextdns / Test_SaveConfig_preservesKeyOrder

Function Test_SaveConfig_preservesKeyOrder

host/service/config_test.go:142–167  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

140}
141
142func Test_SaveConfig_preservesKeyOrder(t *testing.T) {
143 original := "profile abc123\ncache-size 100MB\n"
144 path := writeConfigFile(t, original)
145
146 str := "200MB"
147 profile := &testListEntry{vals: []string{"abc123"}}
148 c := map[string]ConfigEntry{
149 "cache-size": ConfigValue{Value: &str, Default: "0"},
150 "profile": profile,
151 }
152
153 if err := (ConfigFileStorer{File: path}).SaveConfig(c); err != nil {
154 t.Fatal(err)
155 }
156
157 got := readFile(t, path)
158 profileIdx := strings.Index(got, "profile")
159 cacheIdx := strings.Index(got, "cache-size")
160 if profileIdx == -1 || cacheIdx == -1 {
161 t.Fatalf("missing keys in output:\n%s", got)
162 }
163 // profile appeared first in original file, must stay first
164 if profileIdx > cacheIdx {
165 t.Errorf("expected profile before cache-size (original order):\n%s", got)
166 }
167}
168
169func Test_SaveConfig_newKeysAppendedAlphabetically(t *testing.T) {
170 // File only has "profile"; "cache-size" and "debug" are new

Callers

nothing calls this directly

Calls 4

writeConfigFileFunction · 0.85
readFileFunction · 0.85
SaveConfigMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…