27 std::lock_guard lock(
m_mutex );
34 std::lock_guard lock(
m_mutex );
35 return static_cast<int>( std::ranges::count(
m_requests, aUrl ) );
41 return [
this](
const std::string& aUrl,
int& aStatusCode, std::string& aBody, std::string& )
43 std::lock_guard lock(
m_mutex );
53 aStatusCode = it->second.statusCode;
54 aBody = it->second.body;
64 SetResponse( aRootUrl, { 200, R
"({"categories": "categories.json", "parts": "parts"})" } );
66 SetResponse( aRootUrl + "categories.json", { 200, R
"([
67 { "id": "1", "name": "Resistors", "description": "Resistors" },
68 { "id": "2", "name": "Capacitors", "description": "Capacitors" }
71 SetResponse( aRootUrl + "parts/category/1.json", { 200, R
"([
72 { "id": "res-10k", "name": "R_10K", "description": "10 kOhms resistor" },
73 { "id": "res-100k", "name": "R_100K", "description": "100 kOhms resistor" }
76 SetResponse( aRootUrl + "parts/category/2.json", { 200, R
"([
77 { "id": "cap-100n", "name": "C_100n", "description": "100 nF capacitor" }
80 SetResponse( aRootUrl + "parts/res-10k.json", { 200, R
"({
83 "exclude_from_bom": "False",
84 "exclude_from_board": "False",
85 "exclude_from_sim": "False",
86 "description": "10 kOhms resistor",
87 "keywords": "resistor",
88 "footprint_filters": ["Resistor_SMD:R_0603_1608Metric"],
90 "footprint": { "value": "Resistor_SMD:R_0603_1608Metric", "visible": "False" },
91 "value": { "value": "10k" },
92 "reference": { "value": "R" }
96 SetResponse( aRootUrl + "parts/res-100k.json", { 200, R
"({
99 "exclude_from_bom": "False",
100 "exclude_from_board": "False",
101 "exclude_from_sim": "False",
102 "description": "100 kOhms resistor",
104 "footprint": { "value": "Resistor_SMD:R_0603_1608Metric", "visible": "False" },
105 "value": { "value": "100k" },
106 "reference": { "value": "R" }
110 SetResponse( aRootUrl + "parts/cap-100n.json", { 200, R
"({
113 "description": "100 nF capacitor",
115 "footprint": { "value": "Capacitor_SMD:C_0603_1608Metric", "visible": "False" },
116 "value": { "value": "100n" },
117 "reference": { "value": "C" }
std::function< bool(const std::string &aUrl, int &aStatusCode, std::string &aBody, std::string &aError)> RETRIEVER
Allows replacing CURL fetches with a mock for testing.
std::vector< std::string > m_requests
int RequestCount(const std::string &aUrl) const
Number of times aUrl has been requested.
void InstallStandardLibrary(const std::string &aRootUrl)
void SetResponse(const std::string &aUrl, RESPONSE aResponse)
Replace the response served for an exact URL.
std::map< std::string, RESPONSE > m_responses
HTTP_LIB_CONNECTION::RETRIEVER MakeRetriever()