@@ -90,6 +90,8 @@ func TestTrimTag(t *testing.T) {
9090}
9191
9292func TestAggregateGraphData (t * testing.T ) {
93+ query := `{"query":"query{\n characters(filter: {\n \n }){\n info{\n count\n }\n }\n}"}`
94+ rawResponse := `{"data":{"characters":{"info":{"count":758}}}}`
9395 sampleRecord := AnalyticsRecord {
9496 TimeStamp : time .Date (2022 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
9597 Method : "POST" ,
@@ -109,6 +111,8 @@ func TestAggregateGraphData(t *testing.T) {
109111 APIKey : "test-key" ,
110112 TrackPath : true ,
111113 OauthID : "test-id" ,
114+ RawRequest : base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf (requestTemplate , len (query ), query ))),
115+ RawResponse : base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf (responseTemplate , len (rawResponse ), rawResponse ))),
112116 }
113117
114118 compareFields := func (r * require.Assertions , expected , actual map [string ]* Counter ) {
@@ -133,16 +137,12 @@ func TestAggregateGraphData(t *testing.T) {
133137 records := make ([]interface {}, 3 )
134138 for i := range records {
135139 record := sampleRecord
136- query := `{"query":"query{\n characters(filter: {\n \n }){\n info{\n count\n }\n }\n}"}`
137- response := `{"data":{"characters":{"info":{"count":758}}}}`
138- record .RawRequest = base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf (requestTemplate , len (query ), query )))
139- record .RawResponse = base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf (responseTemplate , len (response ), response )))
140140 records [i ] = record
141141 }
142142 return records
143143 },
144144 expectedAggregate : map [string ]GraphRecordAggregate {
145- "test-org " : {
145+ "test-api " : {
146146 Types : map [string ]* Counter {
147147 "Characters" : {Hits : 3 , ErrorTotal : 0 , Success : 3 },
148148 "Info" : {Hits : 3 , ErrorTotal : 0 , Success : 3 },
@@ -163,10 +163,6 @@ func TestAggregateGraphData(t *testing.T) {
163163 records := make ([]interface {}, 3 )
164164 for i := range records {
165165 record := sampleRecord
166- query := `{"query":"query{\n characters(filter: {\n \n }){\n info{\n count\n }\n }\n}"}`
167- response := `{"data":{"characters":{"info":{"count":758}}}}`
168- record .RawRequest = base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf (requestTemplate , len (query ), query )))
169- record .RawResponse = base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf (responseTemplate , len (response ), response )))
170166 if i == 1 {
171167 record .Tags = []string {}
172168 }
@@ -175,7 +171,7 @@ func TestAggregateGraphData(t *testing.T) {
175171 return records
176172 },
177173 expectedAggregate : map [string ]GraphRecordAggregate {
178- "test-org " : {
174+ "test-api " : {
179175 Types : map [string ]* Counter {
180176 "Characters" : {Hits : 2 , ErrorTotal : 0 , Success : 2 },
181177 "Info" : {Hits : 2 , ErrorTotal : 0 , Success : 2 },
@@ -196,19 +192,16 @@ func TestAggregateGraphData(t *testing.T) {
196192 records := make ([]interface {}, 3 )
197193 for i := range records {
198194 record := sampleRecord
199- query := `{"query":"query{\n characters(filter: {\n \n }){\n info{\n count\n }\n }\n}"}`
200- response := `{"data":{"characters":{"info":{"count":758}}}}`
201195 if i == 1 {
202- response = graphErrorResponse
196+ response := graphErrorResponse
197+ record .RawResponse = base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf (responseTemplate , len (response ), response )))
203198 }
204- record .RawRequest = base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf (requestTemplate , len (query ), query )))
205- record .RawResponse = base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf (responseTemplate , len (response ), response )))
206199 records [i ] = record
207200 }
208201 return records
209202 },
210203 expectedAggregate : map [string ]GraphRecordAggregate {
211- "test-org " : {
204+ "test-api " : {
212205 Types : map [string ]* Counter {
213206 "Characters" : {Hits : 3 , ErrorTotal : 1 , Success : 2 },
214207 "Info" : {Hits : 3 , ErrorTotal : 1 , Success : 2 },
@@ -229,10 +222,6 @@ func TestAggregateGraphData(t *testing.T) {
229222 records := make ([]interface {}, 5 )
230223 for i := range records {
231224 record := sampleRecord
232- query := `{"query":"query{\n characters(filter: {\n \n }){\n info{\n count\n }\n }\n}"}`
233- response := `{"data":{"characters":{"info":{"count":758}}}}`
234- record .RawRequest = base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf (requestTemplate , len (query ), query )))
235- record .RawResponse = base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf (responseTemplate , len (response ), response )))
236225 if i == 2 || i == 4 {
237226 record .ResponseCode = 500
238227 }
@@ -241,7 +230,7 @@ func TestAggregateGraphData(t *testing.T) {
241230 return records
242231 },
243232 expectedAggregate : map [string ]GraphRecordAggregate {
244- "test-org " : {
233+ "test-api " : {
245234 Types : map [string ]* Counter {
246235 "Characters" : {Hits : 5 , ErrorTotal : 2 , Success : 3 },
247236 "Info" : {Hits : 5 , ErrorTotal : 2 , Success : 3 },
@@ -325,7 +314,7 @@ func TestAggregateGraphData_Dimension(t *testing.T) {
325314 r := require .New (t )
326315 aggregated := AggregateGraphData (records , "" , 1 )
327316 r .Len (aggregated , 1 )
328- aggre := aggregated ["test-org " ]
317+ aggre := aggregated ["test-api " ]
329318 dimensions := aggre .Dimensions ()
330319 fmt .Println (dimensions )
331320 for d , values := range responsesCheck {
@@ -337,7 +326,7 @@ func TestAggregateGraphData_Dimension(t *testing.T) {
337326 }
338327 }
339328 if ! found {
340- t .Errorf ("item missing from dimensions: NameL %s, Value: %s, Hits:3" , d , v )
329+ t .Errorf ("item missing from dimensions: Name: %s, Value: %s, Hits:3" , d , v )
341330 }
342331 }
343332 }
0 commit comments