(t *testing.T)
| 99 | } |
| 100 | |
| 101 | func TestAtomicLevelText(t *testing.T) { |
| 102 | tests := []struct { |
| 103 | text string |
| 104 | expect zapcore.Level |
| 105 | err bool |
| 106 | }{ |
| 107 | {"debug", DebugLevel, false}, |
| 108 | {"info", InfoLevel, false}, |
| 109 | {"", InfoLevel, false}, |
| 110 | {"warn", WarnLevel, false}, |
| 111 | {"error", ErrorLevel, false}, |
| 112 | {"dpanic", DPanicLevel, false}, |
| 113 | {"panic", PanicLevel, false}, |
| 114 | {"fatal", FatalLevel, false}, |
| 115 | {"foobar", InfoLevel, true}, |
| 116 | } |
| 117 | |
| 118 | for _, tt := range tests { |
| 119 | var lvl AtomicLevel |
| 120 | // Test both initial unmarshaling and overwriting existing value. |
| 121 | for i := 0; i < 2; i++ { |
| 122 | if tt.err { |
| 123 | assert.Error(t, lvl.UnmarshalText([]byte(tt.text)), "Expected unmarshaling %q to fail.", tt.text) |
| 124 | } else { |
| 125 | assert.NoError(t, lvl.UnmarshalText([]byte(tt.text)), "Expected unmarshaling %q to succeed.", tt.text) |
| 126 | } |
| 127 | assert.Equal(t, tt.expect, lvl.Level(), "Unexpected level after unmarshaling.") |
| 128 | lvl.SetLevel(InfoLevel) |
| 129 | } |
| 130 | |
| 131 | // Test marshalling |
| 132 | if tt.text != "" && !tt.err { |
| 133 | lvl.SetLevel(tt.expect) |
| 134 | marshaled, err := lvl.MarshalText() |
| 135 | assert.NoError(t, err, `Unexpected error marshalling level "%v" to text.`, tt.expect) |
| 136 | assert.Equal(t, tt.text, string(marshaled), "Expected marshaled text to match") |
| 137 | assert.Equal(t, tt.text, lvl.String(), "Expected Stringer call to match") |
| 138 | } |
| 139 | } |
| 140 | } |
nothing calls this directly
no test coverage detected