@@ -6,7 +6,7 @@ The ASF licenses this file to You under the Apache License, Version 2.0
66(the "License"); you may not use this file except in compliance with
77the License. You may obtain a copy of the License at
88
9- http://www.apache.org/licenses/LICENSE-2.0
9+ http://www.apache.org/licenses/LICENSE-2.0
1010
1111Unless required by applicable law or agreed to in writing, software
1212distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,14 +18,15 @@ package primitive
1818
1919import (
2020 "fmt"
21- "github.com/apache/rocketmq-client-go/v2/rlog"
2221 "io/ioutil"
2322 "net"
2423 "net/http"
2524 "os"
2625 "strings"
2726 "testing"
2827
28+ "github.com/apache/rocketmq-client-go/v2/rlog"
29+
2930 . "github.com/smartystreets/goconvey/convey"
3031)
3132
@@ -81,6 +82,43 @@ func TestHttpResolverWithGet(t *testing.T) {
8182 })
8283}
8384
85+ func TestHttpResolverWithGetUnitName (t * testing.T ) {
86+ Convey ("Test UpdateNameServerAddress Save Local Snapshot" , t , func () {
87+ srvs := []string {
88+ "192.168.100.1" ,
89+ "192.168.100.2" ,
90+ "192.168.100.3" ,
91+ "192.168.100.4" ,
92+ "192.168.100.5" ,
93+ }
94+ http .HandleFunc ("/nameserver/addrs3-unsh" , func (w http.ResponseWriter , r * http.Request ) {
95+ if r .URL .Query ().Get ("nofix" ) == "1" {
96+ fmt .Fprintf (w , strings .Join (srvs , ";" ))
97+ }
98+ fmt .Fprintf (w , "" )
99+ })
100+ server := & http.Server {Addr : ":0" , Handler : nil }
101+ listener , _ := net .Listen ("tcp" , ":0" )
102+ go server .Serve (listener )
103+
104+ port := listener .Addr ().(* net.TCPAddr ).Port
105+ nameServerDommain := fmt .Sprintf ("http://127.0.0.1:%d/nameserver/addrs3" , port )
106+ rlog .Info ("Temporary Nameserver" , map [string ]interface {}{
107+ "domain" : nameServerDommain ,
108+ })
109+
110+ resolver := NewHttpResolver ("DEFAULT" , nameServerDommain )
111+ resolver .DomainWithUnit ("unsh" )
112+ resolver .Resolve ()
113+
114+ // check snapshot saved
115+ filePath := resolver .getSnapshotFilePath ("DEFAULT" )
116+ body := strings .Join (srvs , ";" )
117+ bs , _ := ioutil .ReadFile (filePath )
118+ So (string (bs ), ShouldEqual , body )
119+ })
120+ }
121+
84122func TestHttpResolverWithSnapshotFile (t * testing.T ) {
85123 Convey ("Test UpdateNameServerAddress Use Local Snapshot" , t , func () {
86124 srvs := []string {
0 commit comments