@@ -26,7 +26,7 @@ import (
2626 "github.com/hashicorp/consul/sdk/testutil"
2727)
2828
29- func TestStateChanged (t * testing.T ) {
29+ func TestStateChangedConnectProxy (t * testing.T ) {
3030 tests := []struct {
3131 name string
3232 ns * structs.NodeService
@@ -108,6 +108,131 @@ func TestStateChanged(t *testing.T) {
108108 },
109109 want : true ,
110110 },
111+ {
112+ name : "different proxy mesh gateway mode" ,
113+ ns : structs .TestNodeServiceAPIGateway (t ),
114+ token : "foo" ,
115+ mutate : func (ns structs.NodeService , token string ) (* structs.NodeService , string ) {
116+ ns .Proxy .MeshGateway .Mode = structs .MeshGatewayModeLocal
117+ return & ns , token
118+ },
119+ want : true ,
120+ },
121+ }
122+
123+ for _ , tt := range tests {
124+ t .Run (tt .name , func (t * testing.T ) {
125+ proxyID := ProxyID {ServiceID : tt .ns .CompoundServiceID ()}
126+ state , err := newState (proxyID , tt .ns , testSource , tt .token , stateConfig {logger : hclog .New (nil )}, rate .NewLimiter (rate .Inf , 1 ))
127+ require .NoError (t , err )
128+ otherNS , otherToken := tt .mutate (* tt .ns , tt .token )
129+ require .Equal (t , tt .want , state .Changed (otherNS , otherToken ))
130+ })
131+ }
132+ }
133+
134+ func TestStateChangedAPIGateway (t * testing.T ) {
135+ tests := []struct {
136+ name string
137+ ns * structs.NodeService
138+ token string
139+ mutate func (ns structs.NodeService , token string ) (* structs.NodeService , string )
140+ want bool
141+ }{
142+ {
143+ name : "nil node service" ,
144+ ns : structs .TestNodeServiceAPIGateway (t ),
145+ mutate : func (ns structs.NodeService , token string ) (* structs.NodeService , string ) {
146+ return nil , token
147+ },
148+ want : true ,
149+ },
150+ {
151+ name : "same service" ,
152+ ns : structs .TestNodeServiceAPIGateway (t ),
153+ mutate : func (ns structs.NodeService , token string ) (* structs.NodeService , string ) {
154+ return & ns , token
155+ }, want : false ,
156+ },
157+ {
158+ name : "same service, different token" ,
159+ ns : structs .TestNodeServiceAPIGateway (t ),
160+ token : "foo" ,
161+ mutate : func (ns structs.NodeService , token string ) (* structs.NodeService , string ) {
162+ return & ns , "bar"
163+ },
164+ want : true ,
165+ },
166+ {
167+ name : "different address" ,
168+ ns : structs .TestNodeServiceAPIGateway (t ),
169+ token : "foo" ,
170+ mutate : func (ns structs.NodeService , token string ) (* structs.NodeService , string ) {
171+ ns .Address = "10.10.10.10"
172+ return & ns , token
173+ },
174+ want : true ,
175+ },
176+ {
177+ name : "different port" ,
178+ ns : structs .TestNodeServiceAPIGateway (t ),
179+ token : "foo" ,
180+ mutate : func (ns structs.NodeService , token string ) (* structs.NodeService , string ) {
181+ ns .Port = 12345
182+ return & ns , token
183+ },
184+ want : true ,
185+ },
186+ {
187+ name : "different service kind" ,
188+ ns : structs .TestNodeServiceAPIGateway (t ),
189+ token : "foo" ,
190+ mutate : func (ns structs.NodeService , token string ) (* structs.NodeService , string ) {
191+ ns .Kind = ""
192+ return & ns , token
193+ },
194+ want : true ,
195+ },
196+ {
197+ name : "different proxy target" ,
198+ ns : structs .TestNodeServiceAPIGateway (t ),
199+ token : "foo" ,
200+ mutate : func (ns structs.NodeService , token string ) (* structs.NodeService , string ) {
201+ ns .Proxy .DestinationServiceName = "badger"
202+ return & ns , token
203+ },
204+ want : true ,
205+ },
206+ {
207+ name : "different proxy upstreams" ,
208+ ns : structs .TestNodeServiceAPIGateway (t ),
209+ token : "foo" ,
210+ mutate : func (ns structs.NodeService , token string ) (* structs.NodeService , string ) {
211+ ns .Proxy .Upstreams = nil
212+ return & ns , token
213+ },
214+ want : true ,
215+ },
216+ {
217+ name : "different mesh gateway mode (local)" ,
218+ ns : structs .TestNodeServiceAPIGateway (t ),
219+ token : "foo" ,
220+ mutate : func (ns structs.NodeService , token string ) (* structs.NodeService , string ) {
221+ ns .Proxy .MeshGateway .Mode = structs .MeshGatewayModeLocal
222+ return & ns , token
223+ },
224+ want : true ,
225+ },
226+ {
227+ name : "different mesh gateway mode (remote)" ,
228+ ns : structs .TestNodeServiceAPIGateway (t ),
229+ token : "foo" ,
230+ mutate : func (ns structs.NodeService , token string ) (* structs.NodeService , string ) {
231+ ns .Proxy .MeshGateway .Mode = structs .MeshGatewayModeRemote
232+ return & ns , token
233+ },
234+ want : true ,
235+ },
111236 }
112237
113238 for _ , tt := range tests {
0 commit comments