(t *testing.T)
| 95 | } |
| 96 | |
| 97 | func 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 | |
| 123 | func Test_SaveConfig_preservesInlineComment(t *testing.T) { |
| 124 | original := "cache-size 100MB # large cache\n" |
nothing calls this directly
no test coverage detected
searching dependent graphs…