-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathAITelemetrySystemTests.cpp
72 lines (59 loc) · 2.31 KB
/
AITelemetrySystemTests.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
// Copyright (c) Microsoft Corporation. All rights reserved.
#if defined __has_include
# if __has_include ("modules/azmon/AITelemetrySystem.hpp")
# include "modules/azmon/AITelemetrySystem.hpp"
# else
/* Compiling without Azure Monitor */
# undef HAVE_MAT_AI
# endif
#endif
#ifdef HAVE_MAT_AI
#include "common/Common.hpp"
#include "common/MockIOfflineStorage.hpp"
#include "common/MockIHttpClient.hpp"
#include "common/MockILogManagerInternal.hpp"
#include "config/RuntimeConfig_Default.hpp"
using namespace testing;
class AITelemetrySystemTests : public StrictMock<Test>
{
protected:
ILogConfiguration logConfig;
RuntimeConfig_Default config;
LogManagerImpl logManagerMock;
MockIOfflineStorage offlineStorageMock;
MockIHttpClient httpClientMock;
std::shared_ptr<ITaskDispatcher> taskDispatcher;
std::unique_ptr<LogSessionDataProvider> logSessionDataProvider;
std::unique_ptr<ITelemetrySystem> system;
protected:
AITelemetrySystemTests() :
config(logConfig),
logManagerMock(logConfig, static_cast<bool>(nullptr))
{
taskDispatcher = PAL::getDefaultTaskDispatcher();
logSessionDataProvider.reset(new LogSessionDataProvider(&offlineStorageMock));
}
};
TEST_F(AITelemetrySystemTests, testDefaultConfiguration)
{
config[CFG_MAP_METASTATS_CONFIG][CFG_INT_METASTATS_INTERVAL] = 30;
config[CFG_MAP_HTTP]["contentEncoding"] = "deflate";
EXPECT_EQ(0, strcmp(COLLECTOR_URL_PROD, config[CFG_STR_COLLECTOR_URL]));
system.reset(new AITelemetrySystem(
logManagerMock, config, offlineStorageMock, httpClientMock,
*taskDispatcher, nullptr, *logSessionDataProvider
));
unsigned int stats = config[CFG_MAP_METASTATS_CONFIG][CFG_INT_METASTATS_INTERVAL];
EXPECT_EQ(0u, stats);
EXPECT_EQ(0, strcmp("gzip", config[CFG_MAP_HTTP]["contentEncoding"]));
EXPECT_EQ(0, strcmp("https://dc.services.visualstudio.com/v2/track", config[CFG_STR_COLLECTOR_URL]));
}
TEST_F(AITelemetrySystemTests, testUrlOverride)
{
config[CFG_STR_COLLECTOR_URL] = "http://localhost";
system.reset(new AITelemetrySystem(
logManagerMock, config, offlineStorageMock, httpClientMock,
*taskDispatcher, nullptr, *logSessionDataProvider));
EXPECT_EQ(0, strcmp("http://localhost", config[CFG_STR_COLLECTOR_URL]));
}
#endif // HAVE_MAT_AI