@@ -169,9 +169,12 @@ func TestPrependInferredRouterAddr(t *testing.T) {
169169 const inferred = "/dns4/agentmesh-one-xyz.a.run.app/tcp/443/wss/p2p/12D3KooWBzUDQCkZhz2rWrYBhpjcCH8VnrRNcwCW6DoF36iADYrY"
170170 const local = "/ip4/127.0.0.1/tcp/8080/ws/p2p/12D3KooWBzUDQCkZhz2rWrYBhpjcCH8VnrRNcwCW6DoF36iADYrY"
171171
172- enrollIn , _ := proto .Marshal (& api.BootstrapEnrollResponse {
172+ enrollIn , err := proto .Marshal (& api.BootstrapEnrollResponse {
173173 RouterAddresses : []string {local },
174174 })
175+ if err != nil {
176+ t .Fatalf ("Marshal BootstrapEnrollResponse: %v" , err )
177+ }
175178 enrollOutBytes , ok := prependInferredRouterAddr ("/enroll" , enrollIn , inferred )
176179 if ! ok {
177180 t .Fatal ("prependInferredRouterAddr(/enroll) returned false" )
@@ -184,10 +187,13 @@ func TestPrependInferredRouterAddr(t *testing.T) {
184187 t .Fatalf ("BootstrapEnrollResponse.RouterAddresses = %v, want [%s %s]" , enrollOut .RouterAddresses , inferred , local )
185188 }
186189
187- regIn , _ := proto .Marshal (& api.EnrollResponse {
190+ regIn , err := proto .Marshal (& api.EnrollResponse {
188191 BiscuitToken : []byte ("tok" ),
189192 RouterAddresses : []string {local },
190193 })
194+ if err != nil {
195+ t .Fatalf ("Marshal EnrollResponse: %v" , err )
196+ }
191197 regOutBytes , ok := prependInferredRouterAddr ("/register" , regIn , inferred )
192198 if ! ok {
193199 t .Fatal ("prependInferredRouterAddr(/register) returned false" )
@@ -204,13 +210,17 @@ func TestPrependInferredRouterAddr(t *testing.T) {
204210 // router gets the inferred address, another router's entry is untouched.
205211 const otherPeer = "12D3KooWDk5pWkyxVERi6kt3TyRZCaXWqg441QEQxaGkn5rWHB21"
206212 const otherAddr = "/dns4/router-b.example.com/tcp/443/wss/p2p/" + otherPeer
207- infoIn , _ := proto .Marshal (& api.ControlPlaneInfoResponse {
213+ infoIn , err := proto .Marshal (& api.ControlPlaneInfoResponse {
208214 RouterAddresses : []string {local },
209215 Routers : []* api.RouterInfo {
210216 {PeerId : "12D3KooWBzUDQCkZhz2rWrYBhpjcCH8VnrRNcwCW6DoF36iADYrY" , Addresses : []string {local }},
211217 {PeerId : otherPeer , Addresses : []string {otherAddr }},
218+ {PeerId : "not-a-peer-id" , Addresses : []string {"/ip4/10.0.0.1/tcp/1/ws" }},
212219 },
213220 })
221+ if err != nil {
222+ t .Fatalf ("Marshal ControlPlaneInfoResponse: %v" , err )
223+ }
214224 infoOutBytes , ok := prependInferredRouterAddr ("/info" , infoIn , inferred )
215225 if ! ok {
216226 t .Fatal ("prependInferredRouterAddr(/info) returned false" )
@@ -222,15 +232,18 @@ func TestPrependInferredRouterAddr(t *testing.T) {
222232 if len (infoOut .RouterAddresses ) != 2 || infoOut .RouterAddresses [0 ] != inferred || infoOut .RouterAddresses [1 ] != local {
223233 t .Fatalf ("ControlPlaneInfoResponse.RouterAddresses = %v, want [%s %s]" , infoOut .RouterAddresses , inferred , local )
224234 }
225- if len (infoOut .Routers ) != 2 {
226- t .Fatalf ("ControlPlaneInfoResponse.Routers has %d entries, want 2 " , len (infoOut .Routers ))
235+ if len (infoOut .Routers ) != 3 {
236+ t .Fatalf ("ControlPlaneInfoResponse.Routers has %d entries, want 3 " , len (infoOut .Routers ))
227237 }
228238 if got := infoOut .Routers [0 ].Addresses ; len (got ) != 2 || got [0 ] != inferred || got [1 ] != local {
229239 t .Fatalf ("Routers[0].Addresses = %v, want [%s %s]" , got , inferred , local )
230240 }
231241 if got := infoOut .Routers [1 ].Addresses ; len (got ) != 1 || got [0 ] != otherAddr {
232242 t .Fatalf ("Routers[1].Addresses = %v, want [%s] (another router's entry must not change)" , got , otherAddr )
233243 }
244+ if got := infoOut .Routers [2 ].Addresses ; len (got ) != 1 || got [0 ] != "/ip4/10.0.0.1/tcp/1/ws" {
245+ t .Fatalf ("Routers[2].Addresses = %v, want the entry with an undecodable peer id untouched" , got )
246+ }
234247
235248 if returnsRouterAddresses ("/refresh" ) {
236249 t .Fatal ("returnsRouterAddresses(/refresh) = true, want false" )
0 commit comments