-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapicrud.cpp
102 lines (85 loc) · 2.16 KB
/
apicrud.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// Created by Rakesh on 04/01/2022.
//
#include <catch2/catch_test_macros.hpp>
#include "../../src/api/api.hpp"
using std::operator ""s;
using std::operator ""sv;
using namespace spt::configdb::api;
using namespace spt::configdb::model;
SCENARIO( "API CRUD test", "api-crud" )
{
GIVEN( "A valid key" )
{
auto key = "key"sv;
WHEN( "Setting a key-value pair" )
{
const auto status = set( key, "value"sv );
REQUIRE( status );
}
AND_WHEN( "Reading the key" )
{
const auto value = get( key );
REQUIRE( value );
REQUIRE( *value == "value"sv );
}
AND_WHEN( "Updating the value" )
{
const auto status = set( key, "value modified"sv );
REQUIRE( status );
}
AND_WHEN( "Reading the key again" )
{
const auto value = get( key );
REQUIRE( value );
REQUIRE( *value == "value modified"sv );
}
AND_WHEN( "Update rejected due to if not exists" )
{
auto opts = RequestData::Options{ true };
auto data = RequestData{ key, "value"sv, opts };
const auto status = set( data );
REQUIRE_FALSE( status );
}
AND_WHEN( "Removing the key" )
{
const auto status = remove( key );
REQUIRE( status );
}
AND_WHEN( "Reading the key after remove" )
{
const auto value = get( key );
REQUIRE_FALSE( value );
}
AND_WHEN( "Removing the key again" )
{
const auto status = remove( key );
REQUIRE( status );
}
AND_WHEN( "Caching the key" )
{
REQUIRE( set( RequestData{ key, "value"sv, RequestData::Options{ 600u, false, true } } ) );
}
AND_WHEN( "Retrieving the cached value" )
{
const auto value = get( key );
REQUIRE( value );
CHECK( *value == "value" );
}
AND_WHEN( "Listing the root node" )
{
// Fails when run together, but succeeds when run by itself.
//REQUIRE_FALSE( list( "/"sv ) );
}
AND_WHEN( "Removing the key" )
{
const auto status = remove( key );
REQUIRE( status );
}
AND_WHEN( "Reading the key after remove" )
{
const auto value = get( key );
REQUIRE_FALSE( value );
}
}
}