@@ -45,13 +45,12 @@ func newMockInfra(t *testing.T, cfg *config.Server) *Infra {
4545 require .NoError (t , err )
4646
4747 infra := & Infra {
48- HomeDir : homeDir ,
49- Logger : logging .DefaultLogger (io .Discard , egv1a1 .LogLevelInfo ),
50- EnvoyGateway : cfg .EnvoyGateway ,
51- proxyContextMap : make (map [string ]* proxyContext ),
52- sdsConfigPath : proxyDir ,
53- Stdout : io .Discard ,
54- Stderr : io .Discard ,
48+ HomeDir : homeDir ,
49+ Logger : logging .DefaultLogger (io .Discard , egv1a1 .LogLevelInfo ),
50+ EnvoyGateway : cfg .EnvoyGateway ,
51+ sdsConfigPath : proxyDir ,
52+ Stdout : io .Discard ,
53+ Stderr : io .Discard ,
5554 }
5655 return infra
5756}
@@ -102,11 +101,10 @@ func TestInfra_runEnvoy_stopEnvoy(t *testing.T) {
102101 stdout := & bytes.Buffer {}
103102 stderr := & bytes.Buffer {}
104103 i := & Infra {
105- proxyContextMap : make (map [string ]* proxyContext ),
106- HomeDir : tmpdir ,
107- Logger : logging .DefaultLogger (stdout , egv1a1 .LogLevelInfo ),
108- Stdout : stdout ,
109- Stderr : stderr ,
104+ HomeDir : tmpdir ,
105+ Logger : logging .DefaultLogger (stdout , egv1a1 .LogLevelInfo ),
106+ Stdout : stdout ,
107+ Stderr : stderr ,
110108 }
111109 // Ensures that run -> stop will successfully stop the envoy and we can
112110 // run it again without any issues.
@@ -116,9 +114,11 @@ func TestInfra_runEnvoy_stopEnvoy(t *testing.T) {
116114 "admin: {address: {socket_address: {address: '127.0.0.1', port_value: 9901}}}" ,
117115 }
118116 i .runEnvoy (t .Context (), "" , "test" , args )
119- require .Len (t , i .proxyContextMap , 1 )
117+ _ , ok := i .proxyContextMap .Load ("test" )
118+ require .True (t , ok , "expected proxy context to be stored" )
120119 i .stopEnvoy ("test" )
121- require .Empty (t , i .proxyContextMap )
120+ _ , ok = i .proxyContextMap .Load ("test" )
121+ require .False (t , ok , "expected proxy context to be removed" )
122122 // If the cleanup didn't work, the error due to "address already in use" will be tried to be written to the nil logger,
123123 // which will panic.
124124 }
@@ -165,11 +165,10 @@ func TestInfra_runEnvoy_OutputRedirection(t *testing.T) {
165165 stderr := buffers [1 ]
166166
167167 i := & Infra {
168- proxyContextMap : make (map [string ]* proxyContext ),
169- HomeDir : tmpdir ,
170- Logger : logging .DefaultLogger (stdout , egv1a1 .LogLevelInfo ),
171- Stdout : stdout ,
172- Stderr : stderr ,
168+ HomeDir : tmpdir ,
169+ Logger : logging .DefaultLogger (stdout , egv1a1 .LogLevelInfo ),
170+ Stdout : stdout ,
171+ Stderr : stderr ,
173172 }
174173
175174 // Run envoy with an invalid config to force it to write to stderr and exit quickly
@@ -179,15 +178,17 @@ func TestInfra_runEnvoy_OutputRedirection(t *testing.T) {
179178 }
180179
181180 i .runEnvoy (t .Context (), "" , "test" , args )
182- require .Len (t , i .proxyContextMap , 1 )
181+ _ , ok := i .proxyContextMap .Load ("test" )
182+ require .True (t , ok , "expected proxy context to be stored" )
183183
184184 // Wait a bit for envoy to fail
185185 require .Eventually (t , func () bool {
186186 return stderr .Len () > 0 || stdout .Len () > 0
187187 }, 5 * time .Second , 100 * time .Millisecond , "expected output to be written to buffers" )
188188
189189 i .stopEnvoy ("test" )
190- require .Empty (t , i .proxyContextMap )
190+ _ , ok = i .proxyContextMap .Load ("test" )
191+ require .False (t , ok , "expected proxy context to be removed" )
191192
192193 // Verify that output was captured in buffers (either stdout or stderr should have content)
193194 totalOutput := stdout .Len () + stderr .Len ()
0 commit comments