| 30 | ) |
| 31 | |
| 32 | func TestLoggerWritesToFile(t *testing.T) { |
| 33 | ctx := context.Background() |
| 34 | |
| 35 | loggerA, _ := LoggerFor(ctx) |
| 36 | loggerA.Name("ScenarioA") |
| 37 | defer loggerA.Close() |
| 38 | defer os.Remove(loggerA.LogFile()) |
| 39 | |
| 40 | loggerA.Log("hello from A") |
| 41 | loggerA.Logf("formatted %s", "message") |
| 42 | loggerA.Info("info msg") |
| 43 | loggerA.Warn("warn msg") |
| 44 | loggerA.Error("error msg") |
| 45 | loggerA.Close() |
| 46 | |
| 47 | content, err := os.ReadFile(loggerA.LogFile()) |
| 48 | require.NoError(t, err) |
| 49 | |
| 50 | lines := string(content) |
| 51 | assert.Contains(t, lines, "hello from A") |
| 52 | assert.Contains(t, lines, "formatted message") |
| 53 | assert.Contains(t, lines, "[INFO ]") |
| 54 | assert.Contains(t, lines, "[WARN ]") |
| 55 | assert.Contains(t, lines, "[ERROR]") |
| 56 | } |
| 57 | |
| 58 | func TestLoggerCaching(t *testing.T) { |
| 59 | ctx := context.Background() |