Skip to content

Commit f839ce2

Browse files
committed
fix: Lifecycle enums were not aligned with the spec
1 parent efc4a13 commit f839ce2

File tree

8 files changed

+63
-4
lines changed

8 files changed

+63
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
## [0.5.3](https://github.com/rdkcentral/firebolt-cpp-client/compare/v0.5.2...0.5.3)
1+
## [Unreleased](https://github.com/rdkcentral/firebolt-cpp-client/compare/v0.5.3...main)
2+
3+
### Fixed
4+
- Enums for Lifecycle.CloseType were not aligned with the spec: `killReload`, `killReactivate`
5+
6+
## [0.5.3](https://github.com/rdkcentral/firebolt-cpp-client/compare/v0.5.2...v0.5.3)
27

38
### Changed
49
- Added protocol selection to the API Test App: `[--legacy | --rpc-v2]`

src/json_types/lifecycle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ namespace Firebolt::Lifecycle::JsonData
2727
inline const Firebolt::JSON::EnumType<::Firebolt::Lifecycle::CloseType> CloseReasonEnum({
2828
{"deactivate", ::Firebolt::Lifecycle::CloseType::DEACTIVATE},
2929
{"unload", ::Firebolt::Lifecycle::CloseType::UNLOAD},
30-
{"kill_reload", ::Firebolt::Lifecycle::CloseType::KILL_RELOAD},
31-
{"kill_reactivate", ::Firebolt::Lifecycle::CloseType::KILL_REACTIVATE},
30+
{"killReload", ::Firebolt::Lifecycle::CloseType::KILL_RELOAD},
31+
{"killReactivate", ::Firebolt::Lifecycle::CloseType::KILL_REACTIVATE},
3232
});
3333

3434
inline const Firebolt::JSON::EnumType<::Firebolt::Lifecycle::LifecycleState> LifecycleStateEnum({

test/json_engine.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
*/
1818
#pragma once
1919

20-
#include "gtest/gtest.h"
2120
#include <firebolt/types.h>
2221
#include <fstream>
22+
#include <gtest/gtest.h>
2323
#include <iostream>
2424
#include <nlohmann/json-schema.hpp>
2525
#include <nlohmann/json.hpp>
@@ -66,6 +66,8 @@ class JsonEngine
6666
return nlohmann::json{};
6767
}
6868

69+
const nlohmann::json operator[](const std::string& key) { return _data[key]; }
70+
6971
nlohmann::json read_json_from_file()
7072
{
7173
std::string filename = UT_OPEN_RPC_FILE;

test/unit/discoveryTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "discovery_impl.h"
2020
#include "json_engine.h"
21+
#include "json_types/common.h"
2122
#include "mock_helper.h"
2223
#include <firebolt/json_types.h>
2324

@@ -27,6 +28,12 @@ class DiscoveryTest : public ::testing::Test, protected MockBase
2728
Firebolt::Discovery::DiscoveryImpl discoveryImpl_{mockHelper};
2829
};
2930

31+
TEST_F(DiscoveryTest, checkEnums)
32+
{
33+
validate_enum("AgePolicy", jsonEngine["x-schemas"]["Policies"]["AgePolicy"]["anyOf"][1]["enum"],
34+
Firebolt::JsonData::AgePolicyEnum);
35+
}
36+
3037
TEST_F(DiscoveryTest, watched)
3138
{
3239
mock("Discovery.watched");

test/unit/lifecycleTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
*/
1818

19+
#include "json_types/lifecycle.h"
1920
#include "lifecycle_impl.h"
2021
#include "mock_helper.h"
2122

@@ -37,6 +38,12 @@ class LifecycleTest : public ::testing::Test, protected MockBase
3738
Firebolt::Lifecycle::LifecycleImpl lifecycleImpl_{mockHelper};
3839
};
3940

41+
TEST_F(LifecycleTest, checkEnums)
42+
{
43+
validate_enum("CloseType", Firebolt::Lifecycle::JsonData::CloseReasonEnum);
44+
validate_enum("LifecycleState", Firebolt::Lifecycle::JsonData::LifecycleStateEnum);
45+
}
46+
4047
TEST_F(LifecycleTest, close)
4148
{
4249
nlohmann::json expectedParams;

test/unit/metricsTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
*/
1818

19+
#include "json_types/metrics.h"
1920
#include "metrics_impl.h"
2021
#include "mock_helper.h"
2122

@@ -25,6 +26,11 @@ class MetricsTest : public ::testing::Test, protected MockBase
2526
Firebolt::Metrics::MetricsImpl metricsImpl_{mockHelper};
2627
};
2728

29+
TEST_F(MetricsTest, checkEnums)
30+
{
31+
validate_enum("ErrorType", Firebolt::Metrics::JsonData::ErrorTypeEnum);
32+
}
33+
2834
TEST_F(MetricsTest, Ready)
2935
{
3036
mock("Metrics.ready");

test/unit/mock_helper.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
#pragma once
2020

2121
#include "json_engine.h"
22+
#include <algorithm>
2223
#include <firebolt/helpers.h>
24+
#include <firebolt/json_types.h>
2325
#include <gmock/gmock.h>
2426

2527
class MockHelper : public Firebolt::Helpers::IHelper
@@ -46,6 +48,30 @@ class MockHelper : public Firebolt::Helpers::IHelper
4648
class MockBase
4749
{
4850
protected:
51+
template <typename T>
52+
void validate_enum(const std::string& enumName, const nlohmann::json& enums,
53+
const Firebolt::JSON::EnumType<T>& enumType)
54+
{
55+
for (const auto& expectedValue : enumType)
56+
{
57+
EXPECT_TRUE(std::find(enums.begin(), enums.end(), expectedValue.first) != enums.end())
58+
<< "Expected enum value: " << expectedValue.first
59+
<< " not found in OpenRPC schema for enum: " << enumName;
60+
}
61+
for (const auto& enumValue : enums)
62+
{
63+
auto it = std::find_if(enumType.begin(), enumType.end(), [&enumValue](const auto& pair)
64+
{ return pair.first == enumValue.get<std::string>(); });
65+
EXPECT_TRUE(it != enumType.end())
66+
<< "An enum: " << enumValue.get<std::string>() << " from OpenRPC schema for enum: " << enumName
67+
<< " is not defined in sources";
68+
}
69+
}
70+
template <typename T> void validate_enum(const std::string& enumName, const Firebolt::JSON::EnumType<T>& enumType)
71+
{
72+
validate_enum(enumName, jsonEngine["components"]["schemas"][enumName]["enum"], enumType);
73+
}
74+
4975
Firebolt::Result<nlohmann::json> getter(const std::string& methodName, const nlohmann::json& parameters)
5076
{
5177
nlohmann::json message;

test/unit/textToSpeechTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
*/
1818

19+
#include "json_types/texttospeech.h"
1920
#include "firebolt/texttospeech.h"
2021
#include "json_engine.h"
2122
#include "mock_helper.h"
@@ -27,6 +28,11 @@ class TextToSpeechTest : public ::testing::Test, protected MockBase
2728
Firebolt::TextToSpeech::TextToSpeechImpl ttsImpl{mockHelper};
2829
};
2930

31+
TEST_F(TextToSpeechTest, checkEnums)
32+
{
33+
validate_enum("SpeechRate", Firebolt::TextToSpeech::JsonData::SpeechRateEnum);
34+
}
35+
3036
TEST_F(TextToSpeechTest, listVoices)
3137
{
3238
mock("TextToSpeech.listvoices");

0 commit comments

Comments
 (0)