buildMemoryMetrics creates fake cgroups memory entries in a temporary dir. Returns the fake cgroups root
(t *testing.T, modules []string, metrics []string)
| 259 | |
| 260 | // buildMemoryMetrics creates fake cgroups memory entries in a temporary dir. Returns the fake cgroups root |
| 261 | func buildMemoryMetrics(t *testing.T, modules []string, metrics []string) string { |
| 262 | tmpRoot := t.TempDir() |
| 263 | tmpDir := path.Join(tmpRoot, string(Memory)) |
| 264 | if err := os.MkdirAll(tmpDir, defaultDirPerm); err != nil { |
| 265 | t.Fatal(err) |
| 266 | } |
| 267 | if err := os.WriteFile(path.Join(tmpDir, "memory.stat"), []byte(memoryData), defaultFilePerm); err != nil { |
| 268 | t.Fatal(err) |
| 269 | } |
| 270 | if err := os.WriteFile(path.Join(tmpDir, "memory.oom_control"), []byte(memoryOomControlData), defaultFilePerm); err != nil { |
| 271 | t.Fatal(err) |
| 272 | } |
| 273 | cnt := 0 |
| 274 | for _, mod := range modules { |
| 275 | for _, metric := range metrics { |
| 276 | var fileName string |
| 277 | if mod == "" { |
| 278 | fileName = path.Join(tmpDir, strings.Join([]string{"memory", metric}, ".")) |
| 279 | } else { |
| 280 | fileName = path.Join(tmpDir, strings.Join([]string{"memory", mod, metric}, ".")) |
| 281 | } |
| 282 | if err := os.WriteFile(fileName, []byte(fmt.Sprintln(cnt)), defaultFilePerm); err != nil { |
| 283 | t.Fatal(err) |
| 284 | } |
| 285 | cnt++ |
| 286 | } |
| 287 | } |
| 288 | return tmpRoot |
| 289 | } |
| 290 | |
| 291 | func Test_getOomControlValue(t *testing.T) { |
| 292 | var ( |
no outgoing calls
no test coverage detected
searching dependent graphs…