(t *testing.T)
| 37 | ) |
| 38 | |
| 39 | func TestAtomicLevelServeHTTP(t *testing.T) { |
| 40 | tests := []struct { |
| 41 | desc string |
| 42 | method string |
| 43 | query string |
| 44 | contentType string |
| 45 | body string |
| 46 | expectedCode int |
| 47 | expectedLevel zapcore.Level |
| 48 | }{ |
| 49 | { |
| 50 | desc: "GET", |
| 51 | method: http.MethodGet, |
| 52 | expectedCode: http.StatusOK, |
| 53 | expectedLevel: zap.InfoLevel, |
| 54 | }, |
| 55 | { |
| 56 | desc: "PUT JSON", |
| 57 | method: http.MethodPut, |
| 58 | expectedCode: http.StatusOK, |
| 59 | expectedLevel: zap.WarnLevel, |
| 60 | body: `{"level":"warn"}`, |
| 61 | }, |
| 62 | { |
| 63 | desc: "PUT URL encoded", |
| 64 | method: http.MethodPut, |
| 65 | expectedCode: http.StatusOK, |
| 66 | expectedLevel: zap.WarnLevel, |
| 67 | contentType: "application/x-www-form-urlencoded", |
| 68 | body: "level=warn", |
| 69 | }, |
| 70 | { |
| 71 | desc: "PUT query parameters", |
| 72 | method: http.MethodPut, |
| 73 | query: "?level=warn", |
| 74 | expectedCode: http.StatusOK, |
| 75 | expectedLevel: zap.WarnLevel, |
| 76 | contentType: "application/x-www-form-urlencoded", |
| 77 | }, |
| 78 | { |
| 79 | desc: "body takes precedence over query", |
| 80 | method: http.MethodPut, |
| 81 | query: "?level=info", |
| 82 | expectedCode: http.StatusOK, |
| 83 | expectedLevel: zap.WarnLevel, |
| 84 | contentType: "application/x-www-form-urlencoded", |
| 85 | body: "level=warn", |
| 86 | }, |
| 87 | { |
| 88 | desc: "JSON ignores query", |
| 89 | method: http.MethodPut, |
| 90 | query: "?level=info", |
| 91 | expectedCode: http.StatusOK, |
| 92 | expectedLevel: zap.WarnLevel, |
| 93 | body: `{"level":"warn"}`, |
| 94 | }, |
| 95 | { |
| 96 | desc: "PUT JSON unrecognized", |
nothing calls this directly
no test coverage detected