@@ -47,13 +47,12 @@ func newMockInfra(t *testing.T, cfg *config.Server) *Infra {
4747 require .NoError (t , err )
4848
4949 infra := & Infra {
50- HomeDir : homeDir ,
51- Logger : logging .DefaultLogger (io .Discard , egv1a1 .LogLevelInfo ),
52- EnvoyGateway : cfg .EnvoyGateway ,
53- proxyContextMap : make (map [string ]* proxyContext ),
54- sdsConfigPath : proxyDir ,
55- Stdout : io .Discard ,
56- Stderr : io .Discard ,
50+ HomeDir : homeDir ,
51+ Logger : logging .DefaultLogger (io .Discard , egv1a1 .LogLevelInfo ),
52+ EnvoyGateway : cfg .EnvoyGateway ,
53+ sdsConfigPath : proxyDir ,
54+ Stdout : io .Discard ,
55+ Stderr : io .Discard ,
5756 }
5857 return infra
5958}
@@ -104,11 +103,10 @@ func TestInfra_runEnvoy_stopEnvoy(t *testing.T) {
104103 stdout := & bytes.Buffer {}
105104 stderr := & bytes.Buffer {}
106105 i := & Infra {
107- proxyContextMap : make (map [string ]* proxyContext ),
108- HomeDir : tmpdir ,
109- Logger : logging .DefaultLogger (stdout , egv1a1 .LogLevelInfo ),
110- Stdout : stdout ,
111- Stderr : stderr ,
106+ HomeDir : tmpdir ,
107+ Logger : logging .DefaultLogger (stdout , egv1a1 .LogLevelInfo ),
108+ Stdout : stdout ,
109+ Stderr : stderr ,
112110 }
113111 // Ensures that run -> stop will successfully stop the envoy and we can
114112 // run it again without any issues.
@@ -118,9 +116,11 @@ func TestInfra_runEnvoy_stopEnvoy(t *testing.T) {
118116 "admin: {address: {socket_address: {address: '127.0.0.1', port_value: 9901}}}" ,
119117 }
120118 i .runEnvoy (t .Context (), "" , "test" , args )
121- require .Len (t , i .proxyContextMap , 1 )
119+ _ , ok := i .proxyContextMap .Load ("test" )
120+ require .True (t , ok , "expected proxy context to be stored" )
122121 i .stopEnvoy ("test" )
123- require .Empty (t , i .proxyContextMap )
122+ _ , ok = i .proxyContextMap .Load ("test" )
123+ require .False (t , ok , "expected proxy context to be removed" )
124124 // If the cleanup didn't work, the error due to "address already in use" will be tried to be written to the nil logger,
125125 // which will panic.
126126 }
@@ -167,11 +167,10 @@ func TestInfra_runEnvoy_OutputRedirection(t *testing.T) {
167167 stderr := buffers [1 ]
168168
169169 i := & Infra {
170- proxyContextMap : make (map [string ]* proxyContext ),
171- HomeDir : tmpdir ,
172- Logger : logging .DefaultLogger (stdout , egv1a1 .LogLevelInfo ),
173- Stdout : stdout ,
174- Stderr : stderr ,
170+ HomeDir : tmpdir ,
171+ Logger : logging .DefaultLogger (stdout , egv1a1 .LogLevelInfo ),
172+ Stdout : stdout ,
173+ Stderr : stderr ,
175174 }
176175
177176 // Run envoy with an invalid config to force it to write to stderr and exit quickly
@@ -181,15 +180,17 @@ func TestInfra_runEnvoy_OutputRedirection(t *testing.T) {
181180 }
182181
183182 i .runEnvoy (t .Context (), "" , "test" , args )
184- require .Len (t , i .proxyContextMap , 1 )
183+ _ , ok := i .proxyContextMap .Load ("test" )
184+ require .True (t , ok , "expected proxy context to be stored" )
185185
186186 // Wait a bit for envoy to fail
187187 require .Eventually (t , func () bool {
188188 return stderr .Len () > 0 || stdout .Len () > 0
189189 }, 5 * time .Second , 100 * time .Millisecond , "expected output to be written to buffers" )
190190
191191 i .stopEnvoy ("test" )
192- require .Empty (t , i .proxyContextMap )
192+ _ , ok = i .proxyContextMap .Load ("test" )
193+ require .False (t , ok , "expected proxy context to be removed" )
193194
194195 // Verify that output was captured in buffers (either stdout or stderr should have content)
195196 totalOutput := stdout .Len () + stderr .Len ()
0 commit comments