summaryrefslogtreecommitdiff
path: root/test/src/gtest_fieldstat.cpp
blob: 9850d7f4841311f118e2740fc9aab10d3b419e1e (plain)
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
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <gtest/gtest.h>
#include "fieldstat.h"
#include "fieldstat_internal.h"

extern struct prometheus_endpoint_instance g_prometheus_endpoint_instance;

TEST(FeildStatAPI, CreateFieldStatInstance)
{
	struct fieldstat_instance *instance = fieldstat_instance_create("test");
	EXPECT_NE(nullptr, instance);
	EXPECT_STREQ("test", instance->name);
}

TEST(FeildStatAPI, FieldStatEnablePrometheusEndpoint)
{
	int ret_enable_prometheus_endpoint = 0;
	int ret_req_prometheus_endpoint = 0;

	ret_enable_prometheus_endpoint = fieldstat_global_enable_prometheus_endpoint(9020, "/metrcis");
	EXPECT_EQ(0, ret_enable_prometheus_endpoint);

	ret_req_prometheus_endpoint = system("curl http://127.0.0.1:9020/metrics");
	EXPECT_EQ(0,ret_req_prometheus_endpoint);
}

TEST(FeildStatAPI, FieldStatSetPrometheusOutput)
{
	struct fieldstat_instance *instance = NULL;
	int ret_enable_prometheus_endpoint = 0;
	int ret_set_prometheus_output = 0;

	instance = fieldstat_instance_create("test");
	EXPECT_STREQ("test", instance->name);

	ret_enable_prometheus_endpoint = fieldstat_global_enable_prometheus_endpoint(9020, "/metrcis");
	EXPECT_EQ(0, ret_enable_prometheus_endpoint);

	ret_set_prometheus_output = fieldstat_set_prometheus_output(instance);
	EXPECT_EQ(0, ret_set_prometheus_output);
	
	EXPECT_EQ(1, g_prometheus_endpoint_instance.running);
	EXPECT_EQ(instance, g_prometheus_endpoint_instance.fs_instance[0]);
	EXPECT_EQ(1, g_prometheus_endpoint_instance.fs_instance_cnt);
}

int main(int argc, char *argv[]) 
{
	testing::InitGoogleTest(&argc, argv);
	return RUN_ALL_TESTS();
    return 0;
}