1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2018 Couchbase, Inc.
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 
18 #include "testapp.h"
19 
20 #include "logger/logger_test_fixture.h"
21 
22 #include <folly/portability/GTest.h>
23 
24 class LoggingTest : public TestappTest,
25                     public ::testing::WithParamInterface<int> {
26 protected:
sendVbCmd(int verbosityLevel)27     void sendVbCmd(int verbosityLevel) {
28         auto& conn = getAdminConnection();
29 
30         BinprotVerbosityCommand cmd;
31         cmd.setLevel(verbosityLevel);
32         conn.sendCommand(cmd);
33 
34         BinprotVerbosityResponse rsp;
35         conn.recvResponse(rsp);
36 
37         // Fail this test if the connection does not return a successful
38         // response
39         ASSERT_TRUE(rsp.isSuccess());
40     }
41 };
42 
TEST_P(LoggingTest, ChangeVerbosity)43 TEST_P(LoggingTest, ChangeVerbosity) {
44     sendVbCmd(GetParam());
45 
46     spdlog::level::level_enum level;
47     switch (GetParam()) {
48     case 0:
49         level = spdlog::level::info;
50         break;
51     case 1:
52         level = spdlog::level::debug;
53         break;
54     default:
55         level = spdlog::level::trace;
56         break;
57     }
58 
59     // The configure function will check the response and fail the test if not
60     // ENGINE_SUCCESS.
61     ewouldblock_engine_configure(ENGINE_ERROR_CODE::ENGINE_SUCCESS,
62                                  EWBEngineMode::CheckLogLevels,
63                                  level,
64                                  "key");
65 }
66 
67 // Test with verbosity values 0, 1, 2
68 INSTANTIATE_TEST_CASE_P(LoggingTests, LoggingTest, ::testing::Range(0, 3), );
69