55 "fmt"
66 "net/http"
77 "net/http/httptest"
8+ "slices"
9+ "strings"
810 "testing"
911 "time"
1012
@@ -13,8 +15,6 @@ import (
1315 "github.com/coder/aibridge"
1416 "github.com/coder/aibridge/mcp"
1517 "github.com/coder/aibridge/tracing"
16- "github.com/google/go-cmp/cmp"
17- "github.com/google/go-cmp/cmp/cmpopts"
1818 "github.com/stretchr/testify/assert"
1919 "github.com/stretchr/testify/require"
2020 "github.com/tidwall/gjson"
@@ -670,13 +670,12 @@ func TestTracePassthrough(t *testing.T) {
670670 require .Len (t , spans , 1 )
671671
672672 assert .Equal (t , spans [0 ].Name (), "Passthrough" )
673- attrs := []attribute.KeyValue {
674- attribute .String (tracing .PassthroughURL , "/v1/models" ),
673+ want := []attribute.KeyValue {
675674 attribute .String (tracing .PassthroughMethod , "GET" ),
675+ attribute .String (tracing .PassthroughURL , "/v1/models" ),
676676 }
677- if attrDiff := cmp .Diff (spans [0 ].Attributes (), attrs , cmpopts .EquateComparable (attribute.KeyValue {}), cmpopts .SortSlices (cmpAttrKeyVal )); attrDiff != "" {
678- t .Errorf ("unexpectet attrs diff: %s" , attrDiff )
679- }
677+ got := slices .SortedFunc (slices .Values (spans [0 ].Attributes ()), cmpAttrKeyVal )
678+ require .Equal (t , want , got )
680679}
681680
682681func TestNewServerProxyManagerTraces (t * testing.T ) {
@@ -714,8 +713,8 @@ func TestNewServerProxyManagerTraces(t *testing.T) {
714713 verifyTraces (t , sr , []expectTrace {{"StreamableHTTPServerProxy.Init.fetchTools" , 1 , codes .Unset }}, attrs )
715714}
716715
717- func cmpAttrKeyVal (a attribute.KeyValue , b attribute.KeyValue ) bool {
718- return a .Key < b .Key
716+ func cmpAttrKeyVal (a attribute.KeyValue , b attribute.KeyValue ) int {
717+ return strings . Compare ( string ( a .Key ), string ( b .Key ))
719718}
720719
721720// checks counts of traces with given name, status and attributes
@@ -729,9 +728,9 @@ func verifyTraces(t *testing.T, spanRecorder *tracetest.SpanRecorder, expect []e
729728 continue
730729 }
731730 found ++
732- if attrDiff := cmp . Diff ( s . Attributes (), attrs , cmpopts . EquateEmpty ( ), cmpopts . EquateComparable (attribute. KeyValue {}), cmpopts . SortSlices ( cmpAttrKeyVal )); attrDiff != "" {
733- t . Errorf ( "unexpectet attrs for span named: %v, diff: %s" , e . name , attrDiff )
734- }
731+ want := slices . SortedFunc ( slices . Values ( attrs ), cmpAttrKeyVal )
732+ got := slices . SortedFunc ( slices . Values ( s . Attributes ()), cmpAttrKeyVal )
733+ require . Equal ( t , want , got )
735734 assert .Equalf (t , e .status , s .Status ().Code , "unexpected status for trace naned: %v got: %v want: %v" , e .name , s .Status ().Code , e .status )
736735 }
737736 if found != e .count {
0 commit comments