@@ -14,12 +14,14 @@ import (
1414)
1515
1616type mockDNSClient struct {
17- msg * dns.Msg
18- rtt time.Duration
19- err error
17+ msg * dns.Msg
18+ rtt time.Duration
19+ err error
20+ lastServer string
2021}
2122
2223func (m * mockDNSClient ) Exchange (msg * dns.Msg , server string ) (* dns.Msg , time.Duration , error ) {
24+ m .lastServer = server
2325 return m .msg , m .rtt , m .err
2426}
2527
@@ -36,7 +38,7 @@ func TestProbeDNSLocalHandler(t *testing.T) {
3638 args map [string ]interface {}
3739 mockClient * mockDNSClient
3840 expectedError string
39- validate func (t * testing.T , result string )
41+ validate func (t * testing.T , result * api. ToolCallResult )
4042 }{
4143 {
4244 name : "success query A record" ,
@@ -50,14 +52,19 @@ func TestProbeDNSLocalHandler(t *testing.T) {
5052 rtt : 10 * time .Millisecond ,
5153 err : nil ,
5254 },
53- validate : func (t * testing.T , content string ) {
55+ validate : func (t * testing.T , result * api. ToolCallResult ) {
5456 var res DNSResult
55- err := json .Unmarshal ([]byte (content ), & res )
57+ err := json .Unmarshal ([]byte (result . Content ), & res )
5658 require .NoError (t , err )
5759 assert .Equal (t , "NOERROR" , res .Rcode )
5860 assert .Equal (t , int64 (10 ), res .LatencyMS )
5961 assert .Len (t , res .Answers , 1 )
6062 assert .Contains (t , res .Answers [0 ], "93.184.216.34" )
63+
64+ // Also check structured content
65+ structured , ok := result .StructuredContent .(DNSResult )
66+ require .True (t , ok )
67+ assert .Equal (t , "NOERROR" , structured .Rcode )
6168 },
6269 },
6370 {
@@ -108,11 +115,44 @@ func TestProbeDNSLocalHandler(t *testing.T) {
108115 rtt : 5 * time .Millisecond ,
109116 err : nil ,
110117 },
111- validate : func (t * testing.T , content string ) {
118+ validate : func (t * testing.T , result * api. ToolCallResult ) {
112119 var res DNSResult
113- err := json .Unmarshal ([]byte (content ), & res )
120+ err := json .Unmarshal ([]byte (result . Content ), & res )
114121 require .NoError (t , err )
115122 assert .Equal (t , "NOERROR" , res .Rcode )
123+
124+ // Also check structured content
125+ structured , ok := result .StructuredContent .(DNSResult )
126+ require .True (t , ok )
127+ assert .Equal (t , "NOERROR" , structured .Rcode )
128+ },
129+ },
130+ {
131+ name : "ipv4 address appends default port" ,
132+ args : map [string ]interface {}{
133+ "server" : "1.1.1.1" ,
134+ "name" : "example.com" ,
135+ },
136+ mockClient : & mockDNSClient {
137+ msg : successMsg ,
138+ rtt : 5 * time .Millisecond ,
139+ },
140+ validate : func (t * testing.T , result * api.ToolCallResult ) {
141+ assert .Equal (t , "1.1.1.1:53" , activeDNSClient .(* mockDNSClient ).lastServer )
142+ },
143+ },
144+ {
145+ name : "ipv6 address appends default port" ,
146+ args : map [string ]interface {}{
147+ "server" : "2001:4860:4860::8888" ,
148+ "name" : "example.com" ,
149+ },
150+ mockClient : & mockDNSClient {
151+ msg : successMsg ,
152+ rtt : 5 * time .Millisecond ,
153+ },
154+ validate : func (t * testing.T , result * api.ToolCallResult ) {
155+ assert .Equal (t , "[2001:4860:4860::8888]:53" , activeDNSClient .(* mockDNSClient ).lastServer )
116156 },
117157 },
118158 }
@@ -149,7 +189,7 @@ func TestProbeDNSLocalHandler(t *testing.T) {
149189 require .NotNil (t , result )
150190 require .NoError (t , result .Error )
151191 if tt .validate != nil {
152- tt .validate (t , result . Content )
192+ tt .validate (t , result )
153193 }
154194 }
155195 })
0 commit comments