MCPcopy
hub / github.com/nextdns/nextdns / Test_SaveConfig_preservesFullLineComments

Function Test_SaveConfig_preservesFullLineComments

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

Source from the content-addressed store, hash-verified

95}
96
97func Test_SaveConfig_preservesFullLineComments(t *testing.T) {
98 original := "# cache setting\ncache-size 100MB\n"
99 path := writeConfigFile(t, original)
100
101 str := "200MB"
102 c := map[string]ConfigEntry{
103 "cache-size": ConfigValue{Value: &str, Default: "0"},
104 }
105
106 if err := (ConfigFileStorer{File: path}).SaveConfig(c); err != nil {
107 t.Fatal(err)
108 }
109
110 got := readFile(t, path)
111 if !strings.Contains(got, "# cache setting\n") {
112 t.Errorf("expected full-line comment to be preserved:\n%s", got)
113 }
114 if !strings.Contains(got, "cache-size 200MB\n") {
115 t.Errorf("expected updated value:\n%s", got)
116 }
117 // Comment must appear immediately before the key
118 if !strings.Contains(got, "# cache setting\ncache-size 200MB\n") {
119 t.Errorf("comment not directly above key:\n%s", got)
120 }
121}
122
123func Test_SaveConfig_preservesInlineComment(t *testing.T) {
124 original := "cache-size 100MB # large cache\n"

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…