+func TestSetLogLevel(t *testing.T) {
+ assertions := require.New(t)
+
+ type args struct {
+ logLevel string
+ }
+ tests := []struct {
+ name string
+ args args
+ wantedStatus int
+ wantedBody string
+ }{
+ {
+ name: "Set to valid log level, should return OK",
+ args: args{
+ logLevel: "Debug",
+ },
+ wantedStatus: http.StatusOK,
+ },
+ {
+ name: "Set to invalid log level, should return BadRequest",
+ args: args{
+ logLevel: "bad",
+ },
+ wantedStatus: http.StatusBadRequest,
+ wantedBody: "Invalid log level: bad",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ callbackHandlerUnderTest := NewProducerCallbackHandler(nil)
+
+ handler := http.HandlerFunc(callbackHandlerUnderTest.setLogLevel)
+ responseRecorder := httptest.NewRecorder()
+ r, _ := http.NewRequest(http.MethodPut, "/admin/log?level="+tt.args.logLevel, nil)
+
+ handler.ServeHTTP(responseRecorder, r)
+
+ assertions.Equal(tt.wantedStatus, responseRecorder.Code, tt.name)
+ assertions.Contains(responseRecorder.Body.String(), tt.wantedBody, tt.name)
+ })
+ }
+}
+