(t *testing.T)
| 159 | } |
| 160 | |
| 161 | func TestDisableLevelTruncation(t *testing.T) { |
| 162 | entry := &Entry{ |
| 163 | Time: time.Now(), |
| 164 | Message: "testing", |
| 165 | } |
| 166 | keys := []string{} |
| 167 | timestampFormat := "Mon Jan 2 15:04:05 -0700 MST 2006" |
| 168 | checkDisableTruncation := func(disabled bool, level Level) { |
| 169 | tf := &TextFormatter{DisableLevelTruncation: disabled} |
| 170 | var b bytes.Buffer |
| 171 | entry.Level = level |
| 172 | tf.printColored(&b, entry, keys, nil, timestampFormat) |
| 173 | logLine := (&b).String() |
| 174 | if disabled { |
| 175 | expected := strings.ToUpper(level.String()) |
| 176 | if !strings.Contains(logLine, expected) { |
| 177 | t.Errorf("level string expected to be %s when truncation disabled", expected) |
| 178 | } |
| 179 | } else { |
| 180 | expected := strings.ToUpper(level.String()) |
| 181 | if len(level.String()) > 4 { |
| 182 | if strings.Contains(logLine, expected) { |
| 183 | t.Errorf("level string %s expected to be truncated to %s when truncation is enabled", expected, expected[0:4]) |
| 184 | } |
| 185 | } else { |
| 186 | if !strings.Contains(logLine, expected) { |
| 187 | t.Errorf("level string expected to be %s when truncation is enabled and level string is below truncation threshold", expected) |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | checkDisableTruncation(true, DebugLevel) |
| 194 | checkDisableTruncation(true, InfoLevel) |
| 195 | checkDisableTruncation(false, ErrorLevel) |
| 196 | checkDisableTruncation(false, InfoLevel) |
| 197 | } |
| 198 | |
| 199 | func TestPadLevelText(t *testing.T) { |
| 200 | // A note for future maintainers / committers: |
nothing calls this directly
no test coverage detected