Skip to content

Commit fe4e413

Browse files
committed
feat: Update test telemetry handle initialization
1 parent 2f30e40 commit fe4e413

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

aitelemetry/telemetrywrapper_test.go

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import (
1515
)
1616

1717
var (
18-
th TelemetryHandle
18+
th1 TelemetryHandle
19+
th2 TelemetryHandle
20+
aiConfig AIConfig
1921
hostAgentUrl = "localhost:3501"
2022
getCloudResponse = "AzurePublicCloud"
2123
httpURL = "http://" + hostAgentUrl
@@ -54,6 +56,28 @@ func TestMain(m *testing.M) {
5456
return
5557
}
5658

59+
aiConfig = AIConfig{
60+
AppName: "testapp",
61+
AppVersion: "v1.0.26",
62+
BatchSize: 4096,
63+
BatchInterval: 2,
64+
RefreshTimeout: 10,
65+
GetEnvRetryCount: 1,
66+
GetEnvRetryWaitTimeInSecs: 2,
67+
DebugMode: true,
68+
DisableMetadataRefreshThread: true,
69+
}
70+
71+
th1, err = NewAITelemetry(httpURL, "00ca2a73-c8d6-4929-a0c2-cf84545ec225", aiConfig)
72+
if th1 == nil {
73+
fmt.Printf("Error initializing AI telemetry: %v", err)
74+
}
75+
76+
th2, err = NewWithConnectionString(connectionString, aiConfig)
77+
if th2 == nil {
78+
fmt.Printf("Error initializing AI telemetry with connection string: %v", err)
79+
}
80+
5781
exitCode := m.Run()
5882

5983
if runtime.GOOS == "linux" {
@@ -78,15 +102,6 @@ func handleGetCloud(w http.ResponseWriter, req *http.Request) {
78102
func TestEmptyAIKey(t *testing.T) {
79103
var err error
80104

81-
aiConfig := AIConfig{
82-
AppName: "testapp",
83-
AppVersion: "v1.0.26",
84-
BatchSize: 4096,
85-
BatchInterval: 2,
86-
RefreshTimeout: 10,
87-
DebugMode: true,
88-
DisableMetadataRefreshThread: true,
89-
}
90105
_, err = NewAITelemetry(httpURL, "", aiConfig)
91106
if err == nil {
92107
t.Errorf("Error initializing AI telemetry:%v", err)
@@ -101,17 +116,6 @@ func TestEmptyAIKey(t *testing.T) {
101116
func TestNewAITelemetry(t *testing.T) {
102117
var err error
103118

104-
aiConfig := AIConfig{
105-
AppName: "testapp",
106-
AppVersion: "v1.0.26",
107-
BatchSize: 4096,
108-
BatchInterval: 2,
109-
RefreshTimeout: 10,
110-
GetEnvRetryCount: 1,
111-
GetEnvRetryWaitTimeInSecs: 2,
112-
DebugMode: true,
113-
DisableMetadataRefreshThread: true,
114-
}
115119
th1, err := NewAITelemetry(httpURL, "00ca2a73-c8d6-4929-a0c2-cf84545ec225", aiConfig)
116120
if th1 == nil {
117121
t.Errorf("Error initializing AI telemetry: %v", err)
@@ -131,7 +135,8 @@ func TestTrackMetric(t *testing.T) {
131135
}
132136

133137
metric.CustomDimensions["dim1"] = "col1"
134-
th.TrackMetric(metric)
138+
th1.TrackMetric(metric)
139+
th2.TrackMetric(metric)
135140
}
136141

137142
func TestTrackLog(t *testing.T) {
@@ -142,7 +147,8 @@ func TestTrackLog(t *testing.T) {
142147
}
143148

144149
report.CustomDimensions["dim1"] = "col1"
145-
th.TrackLog(report)
150+
th1.TrackLog(report)
151+
th2.TrackLog(report)
146152
}
147153

148154
func TestTrackEvent(t *testing.T) {
@@ -154,31 +160,23 @@ func TestTrackEvent(t *testing.T) {
154160

155161
event.Properties["P1"] = "V1"
156162
event.Properties["P2"] = "V2"
157-
th.TrackEvent(event)
163+
th1.TrackEvent(event)
164+
th2.TrackEvent(event)
158165
}
159166

160167
func TestFlush(t *testing.T) {
161-
th.Flush()
168+
th1.Flush()
169+
th2.Flush()
162170
}
163171

164172
func TestClose(t *testing.T) {
165-
th.Close(10)
173+
th1.Close(10)
174+
th2.Close(10)
166175
}
167176

168177
func TestClosewithoutSend(t *testing.T) {
169178
var err error
170179

171-
aiConfig := AIConfig{
172-
AppName: "testapp",
173-
AppVersion: "v1.0.26",
174-
BatchSize: 4096,
175-
BatchInterval: 2,
176-
DisableMetadataRefreshThread: true,
177-
RefreshTimeout: 10,
178-
GetEnvRetryCount: 1,
179-
GetEnvRetryWaitTimeInSecs: 2,
180-
}
181-
182180
thtest, err := NewAITelemetry(httpURL, "00ca2a73-c8d6-4929-a0c2-cf84545ec225", aiConfig)
183181
if thtest == nil {
184182
t.Errorf("Error initializing AI telemetry:%v", err)

0 commit comments

Comments
 (0)