| 1 | package logr |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | ) |
| 6 | |
| 7 | func TestLevelFromString(t *testing.T) { |
| 8 | scenarios := []struct { |
| 9 | input string |
| 10 | expected Level |
| 11 | expectedErr error |
| 12 | }{ |
| 13 | {"DEBUG", LevelDebug, nil}, |
| 14 | {"debug", LevelDebug, nil}, |
| 15 | {"INFO", LevelInfo, nil}, |
| 16 | {"info", LevelInfo, nil}, |
| 17 | {"WARN", LevelWarn, nil}, |
| 18 | {"warn", LevelWarn, nil}, |
| 19 | {"ERROR", LevelError, nil}, |
| 20 | {"error", LevelError, nil}, |
| 21 | {"", LevelDebug, ErrInvalidLevelString}, |
| 22 | {"invalid", LevelDebug, ErrInvalidLevelString}, |
| 23 | } |
| 24 | for _, scenario := range scenarios { |
| 25 | t.Run(scenario.input, func(t *testing.T) { |
| 26 | actual, err := LevelFromString(scenario.input) |
| 27 | if actual != scenario.expected { |
| 28 | t.Errorf("expected %s, got %s", scenario.expected, actual) |
| 29 | } |
| 30 | if err != scenario.expectedErr { |
| 31 | t.Errorf("expected %v, got %v", scenario.expectedErr, err) |
| 32 | } |
| 33 | }) |
| 34 | } |
| 35 | } |