blob: 2c603c4f69d68a2e255a84e1e0c2d002847b260e [file] [log] [blame]
Brandon Kim559cb012024-05-03 09:12:07 +00001// Copyright 2024 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "bm_instance.hpp"
16#include "commands.hpp"
17#include "handler_mock.hpp"
18#include "helper.hpp"
19
20#include <string>
21#include <vector>
22
23#include <gtest/gtest.h>
24
25namespace google
26{
27namespace ipmi
28{
29
30using testing::_;
31using ::testing::Return;
32using ::testing::StrEq;
33
34TEST(GetBMInstancePropertyTest, InvalidRequestSize)
35{
36 std::vector<uint8_t> request = {};
37
38 HandlerMock hMock;
39 EXPECT_EQ(::ipmi::responseReqDataLenInvalid(),
40 getBMInstanceProperty(request, &hMock));
41}
42
43TEST(GetBMInstancePropertyTest, InvalidCommand)
44{
45 std::vector<uint8_t> request = {1};
46 std::string expectedOutput(64, 'a');
47
48 HandlerMock hMock;
49 EXPECT_CALL(hMock, getBMInstanceProperty(1))
50 .WillOnce(Return(expectedOutput));
51 EXPECT_EQ(::ipmi::responseInvalidCommand(),
52 getBMInstanceProperty(request, &hMock));
53}
54
55TEST(GetBMInstancePropertyTest, ValidRequest)
56{
57 std::vector<uint8_t> request = {2};
58 std::string expectedOutput = "asdf";
59
60 HandlerMock hMock;
61 EXPECT_CALL(hMock, getBMInstanceProperty(2))
62 .WillOnce(Return(expectedOutput));
63
64 auto reply = getBMInstanceProperty(request, &hMock);
65 auto result = ValidateReply(reply);
66 auto& data = result.second;
67
68 EXPECT_EQ(sizeof(struct BMInstancePropertyReply) + expectedOutput.size(),
69 data.size());
70 EXPECT_EQ(SysOEMCommands::SysGetBMInstanceProperty, result.first);
71 EXPECT_THAT(std::string(data.begin() + 1, data.end()),
72 StrEq(expectedOutput));
73}
74
75} // namespace ipmi
76} // namespace google