@@ -17,6 +17,8 @@ func TestGetOperations(t *testing.T) {
1717 conn , cleanup := sqltest .Harness (t )
1818 q := sql .New (conn )
1919
20+ defer conn .Close (context .Background ())
21+
2022 t .Run ("should return nothing when no operations exist" , func (t * testing.T ) {
2123 require .Nil (t , cleanup ())
2224
@@ -79,6 +81,8 @@ func TestGetServices(t *testing.T) {
7981 conn , cleanup := sqltest .Harness (t )
8082 q := sql .New (conn )
8183
84+ defer conn .Close (context .Background ())
85+
8286 t .Run ("should return nothing when no services exist" , func (t * testing.T ) {
8387 require .Nil (t , cleanup ())
8488
@@ -111,6 +115,8 @@ func TestSpans(t *testing.T) {
111115 conn , cleanup := sqltest .Harness (t )
112116 q := sql .New (conn )
113117
118+ defer conn .Close (context .Background ())
119+
114120 t .Run ("should be able to write a span" , func (t * testing.T ) {
115121 require .Nil (t , cleanup ())
116122
@@ -186,4 +192,79 @@ func TestSpans(t *testing.T) {
186192 _ = queried
187193
188194 })
195+
196+ t .Run ("should be able to write a span" , func (t * testing.T ) {
197+ require .Nil (t , cleanup ())
198+
199+ err := q .UpsertService (ctx , "service-1" )
200+ require .Nil (t , err )
201+
202+ serviceID , err := q .GetServiceID (ctx , "service-1" )
203+ require .Nil (t , err )
204+
205+ err = q .UpsertOperation (ctx , sql.UpsertOperationParams {Name : "operation-1" , ServiceID : serviceID , Kind : sql .SpankindClient })
206+ require .Nil (t , err )
207+
208+ operationID , err := q .GetOperationID (ctx , sql.GetOperationIDParams {Name : "operation-1" , ServiceID : serviceID , Kind : sql .SpankindClient })
209+ require .Nil (t , err )
210+
211+ _ , err = q .InsertSpan (ctx , sql.InsertSpanParams {
212+ SpanID : []byte {0 , 0 , 0 , 1 },
213+ TraceID : []byte {0 , 0 , 0 , 0 },
214+ OperationID : operationID ,
215+ Flags : 0 ,
216+ StartTime : pgtype.Timestamp {Time : time .Now (), Valid : true },
217+ Duration : pgtype.Interval {Microseconds : 1000 , Valid : true },
218+ Tags : []byte ("[]" ),
219+ ServiceID : serviceID ,
220+ ProcessID : "" ,
221+ ProcessTags : []byte ("[]" ),
222+ Warnings : []string {},
223+ Kind : sql .SpankindClient ,
224+ Logs : []byte ("null" ),
225+ Refs : []byte ("[]" ),
226+ })
227+ require .Nil (t , err )
228+
229+ _ , err = q .InsertSpan (ctx , sql.InsertSpanParams {
230+ SpanID : []byte {0 , 0 , 0 , 0 },
231+ TraceID : []byte {0 , 0 , 0 , 1 },
232+ OperationID : operationID ,
233+ Flags : 0 ,
234+ StartTime : pgtype.Timestamp {Time : time .Now (), Valid : true },
235+ Duration : pgtype.Interval {Microseconds : 1000 , Valid : true },
236+ Tags : []byte ("[]" ),
237+ ServiceID : serviceID ,
238+ ProcessID : "" ,
239+ ProcessTags : []byte ("null" ),
240+ Warnings : []string {},
241+ Kind : sql .SpankindClient ,
242+ Logs : []byte ("null" ),
243+ Refs : []byte ("[]" ),
244+ })
245+ require .Nil (t , err )
246+
247+ _ , err = q .InsertSpan (ctx , sql.InsertSpanParams {
248+ SpanID : []byte {0 , 0 , 0 , 0 },
249+ TraceID : []byte {0 , 0 , 0 , 2 },
250+ OperationID : operationID ,
251+ Flags : 0 ,
252+ StartTime : pgtype.Timestamp {Time : time .Now (), Valid : true },
253+ Duration : pgtype.Interval {Microseconds : 1000 , Valid : true },
254+ Tags : []byte ("[]" ),
255+ ServiceID : serviceID ,
256+ ProcessID : "" ,
257+ ProcessTags : []byte ("[]" ),
258+ Warnings : []string {},
259+ Kind : sql .SpankindClient ,
260+ Logs : []byte ("null" ),
261+ Refs : []byte ("[]" ),
262+ })
263+ require .Nil (t , err )
264+
265+ queried , err := q .FindTraceIDs (ctx , sql.FindTraceIDsParams {NumTraces : 1 })
266+ require .Nil (t , err )
267+
268+ require .Len (t , queried , 1 )
269+ })
189270}
0 commit comments