forked from berthubert/simplomon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestrunner.cc
42 lines (34 loc) · 1.02 KB
/
testrunner.cc
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
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <algorithm> // std::move() and friends
#include <stdexcept>
#include <string>
#include <thread>
#include <unistd.h> //unlink(), usleep()
#include <unordered_map>
#include "doctest.h"
#include "httplib.h"
#include "nlohmann/json.hpp"
#include "simplomon.hh"
using namespace std;
vector<CheckerNotifierCombo> g_checkers;
std::vector<std::shared_ptr<Notifier>> g_notifiers;
TEST_CASE("alert filter test") {
AlertFilter af1;
time_t now = time(nullptr);
af1.reportAlert(now-4000);
af1.reportAlert(now-3000);
af1.reportAlert(now-2000);
af1.reportAlert(now-1000);
af1.reportAlert(now);
CHECK(af1.shouldAlert(2, 900) == false);
CHECK(af1.shouldAlert(1, 1001) == true);
CHECK(af1.shouldAlert(2, 1001) == true);
CHECK(af1.shouldAlert(4, 3001) == true);
CHECK(af1.shouldAlert(4, 5000) == true);
CHECK(af1.shouldAlert(5, 5001) == false);
AlertFilter af2;
now=time(nullptr);
af2.reportAlert(now);
af2.reportAlert(now-60);
CHECK(af2.shouldAlert(2, 60) == true);
}