@@ -26,6 +26,23 @@ func Test_runCmd(t *testing.T) {
2626 assert .FileExists (t , globalTestConfigFile , "configInitCmd should create a config file" )
2727
2828 var waitGroup sync.WaitGroup
29+
30+ waitGroup .Add (1 )
31+ go func (waitGroup * sync.WaitGroup ) {
32+ // Test run command.
33+ output := capturer .CaptureOutput (func () {
34+ _ , err := executeCommandC (rootCmd , "run" , "-c" , globalTestConfigFile , "-p" , pluginTestConfigFile )
35+ require .NoError (t , err , "run command should not have returned an error" )
36+ })
37+ // Print the output for debugging purposes.
38+ runCmd .Print (output )
39+ // Check if GatewayD started and stopped correctly.
40+ assert .Contains (t , output , "GatewayD is running" )
41+ assert .Contains (t , output , "Stopped all servers\n " )
42+
43+ waitGroup .Done ()
44+ }(& waitGroup )
45+
2946 waitGroup .Add (1 )
3047 go func (waitGroup * sync.WaitGroup ) {
3148 time .Sleep (100 * time .Millisecond )
@@ -34,7 +51,7 @@ func Test_runCmd(t *testing.T) {
3451 context .Background (),
3552 nil ,
3653 nil ,
37- nil ,
54+ metricsServer ,
3855 nil ,
3956 loggers [config .Default ],
4057 servers ,
@@ -44,38 +61,15 @@ func Test_runCmd(t *testing.T) {
4461 waitGroup .Done ()
4562 }(& waitGroup )
4663
47- waitGroup .Add (1 )
48- go func (waitGroup * sync.WaitGroup ) {
49- // Test run command.
50- output := capturer .CaptureOutput (func () {
51- _ , err := executeCommandC (rootCmd , "run" , "-c" , globalTestConfigFile , "-p" , pluginTestConfigFile )
52- require .NoError (t , err , "run command should not have returned an error" )
53- })
54- // Print the output for debugging purposes.
55- runCmd .Print (output )
56- // Check if GatewayD started and stopped correctly.
57- assert .Contains (t ,
58- output ,
59- "GatewayD is running" ,
60- "run command should have returned the correct output" )
61- assert .Contains (t ,
62- output ,
63- "Stopped all servers\n " ,
64- "run command should have returned the correct output" )
65-
66- waitGroup .Done ()
67- }(& waitGroup )
68-
6964 waitGroup .Wait ()
7065
7166 // Clean up.
7267 require .NoError (t , os .Remove (pluginTestConfigFile ))
7368 require .NoError (t , os .Remove (globalTestConfigFile ))
7469}
7570
76- // Test_runCmdWithMultiTenancy tests the run command with multi-tenancy enabled.
77- // Note: This test needs two instances of PostgreSQL running on ports 5432 and 5433.
78- func Test_runCmdWithMultiTenancy (t * testing.T ) {
71+ // Test_runCmdWithTLS tests the run command with TLS enabled on the server.
72+ func Test_runCmdWithTLS (t * testing.T ) {
7973 // Create a test plugins config file.
8074 _ , err := executeCommandC (rootCmd , "plugin" , "init" , "--force" , "-p" , pluginTestConfigFile )
8175 require .NoError (t , err , "plugin init command should not have returned an error" )
@@ -84,15 +78,36 @@ func Test_runCmdWithMultiTenancy(t *testing.T) {
8478 stopChan = make (chan struct {})
8579
8680 var waitGroup sync.WaitGroup
81+ // TODO: Test client certificate authentication.
82+
8783 waitGroup .Add (1 )
8884 go func (waitGroup * sync.WaitGroup ) {
89- time .Sleep (500 * time .Millisecond )
85+ // Test run command.
86+ output := capturer .CaptureOutput (func () {
87+ _ , err := executeCommandC (rootCmd , "run" , "-c" , globalTLSTestConfigFile , "-p" , pluginTestConfigFile )
88+ require .NoError (t , err , "run command should not have returned an error" )
89+ })
90+
91+ // Print the output for debugging purposes.
92+ runCmd .Print (output )
93+
94+ // Check if GatewayD started and stopped correctly.
95+ assert .Contains (t , output , "GatewayD is running" )
96+ assert .Contains (t , output , "TLS is enabled" )
97+ assert .Contains (t , output , "Stopped all servers\n " )
98+
99+ waitGroup .Done ()
100+ }(& waitGroup )
101+
102+ waitGroup .Add (1 )
103+ go func (waitGroup * sync.WaitGroup ) {
104+ time .Sleep (100 * time .Millisecond )
90105
91106 StopGracefully (
92107 context .Background (),
93108 nil ,
94109 nil ,
95- nil ,
110+ metricsServer ,
96111 nil ,
97112 loggers [config .Default ],
98113 servers ,
@@ -102,6 +117,24 @@ func Test_runCmdWithMultiTenancy(t *testing.T) {
102117 waitGroup .Done ()
103118 }(& waitGroup )
104119
120+ waitGroup .Wait ()
121+
122+ // Clean up.
123+ require .NoError (t , os .Remove (pluginTestConfigFile ))
124+ }
125+
126+ // Test_runCmdWithMultiTenancy tests the run command with multi-tenancy enabled.
127+ // Note: This test needs two instances of PostgreSQL running on ports 5432 and 5433.
128+ func Test_runCmdWithMultiTenancy (t * testing.T ) {
129+ // Create a test plugins config file.
130+ _ , err := executeCommandC (rootCmd , "plugin" , "init" , "--force" , "-p" , pluginTestConfigFile )
131+ require .NoError (t , err , "plugin init command should not have returned an error" )
132+ assert .FileExists (t , pluginTestConfigFile , "plugin init command should have created a config file" )
133+
134+ stopChan = make (chan struct {})
135+
136+ var waitGroup sync.WaitGroup
137+
105138 waitGroup .Add (1 )
106139 go func (waitGroup * sync.WaitGroup ) {
107140 // Test run command.
@@ -123,6 +156,24 @@ func Test_runCmdWithMultiTenancy(t *testing.T) {
123156 waitGroup .Done ()
124157 }(& waitGroup )
125158
159+ waitGroup .Add (1 )
160+ go func (waitGroup * sync.WaitGroup ) {
161+ time .Sleep (500 * time .Millisecond )
162+
163+ StopGracefully (
164+ context .Background (),
165+ nil ,
166+ nil ,
167+ metricsServer ,
168+ nil ,
169+ loggers [config .Default ],
170+ servers ,
171+ stopChan ,
172+ )
173+
174+ waitGroup .Done ()
175+ }(& waitGroup )
176+
126177 waitGroup .Wait ()
127178
128179 // Clean up.
@@ -164,6 +215,23 @@ func Test_runCmdWithCachePlugin(t *testing.T) {
164215 assert .Contains (t , output , "Name: gatewayd-plugin-cache" )
165216
166217 var waitGroup sync.WaitGroup
218+
219+ waitGroup .Add (1 )
220+ go func (waitGroup * sync.WaitGroup ) {
221+ // Test run command.
222+ output := capturer .CaptureOutput (func () {
223+ _ , err := executeCommandC (rootCmd , "run" , "-c" , globalTestConfigFile , "-p" , pluginTestConfigFile )
224+ require .NoError (t , err , "run command should not have returned an error" )
225+ })
226+ // Print the output for debugging purposes.
227+ runCmd .Print (output )
228+ // Check if GatewayD started and stopped correctly.
229+ assert .Contains (t , output , "GatewayD is running" )
230+ assert .Contains (t , output , "Stopped all servers\n " )
231+
232+ waitGroup .Done ()
233+ }(& waitGroup )
234+
167235 waitGroup .Add (1 )
168236 go func (waitGroup * sync.WaitGroup ) {
169237 time .Sleep (time .Second )
@@ -172,7 +240,7 @@ func Test_runCmdWithCachePlugin(t *testing.T) {
172240 context .Background (),
173241 nil ,
174242 nil ,
175- nil ,
243+ metricsServer ,
176244 nil ,
177245 loggers [config .Default ],
178246 servers ,
@@ -182,28 +250,6 @@ func Test_runCmdWithCachePlugin(t *testing.T) {
182250 waitGroup .Done ()
183251 }(& waitGroup )
184252
185- waitGroup .Add (1 )
186- go func (waitGroup * sync.WaitGroup ) {
187- // Test run command.
188- output := capturer .CaptureOutput (func () {
189- _ , err := executeCommandC (rootCmd , "run" , "-c" , globalTestConfigFile , "-p" , pluginTestConfigFile )
190- require .NoError (t , err , "run command should not have returned an error" )
191- })
192- // Print the output for debugging purposes.
193- runCmd .Print (output )
194- // Check if GatewayD started and stopped correctly.
195- assert .Contains (t ,
196- output ,
197- "GatewayD is running" ,
198- "run command should have returned the correct output" )
199- assert .Contains (t ,
200- output ,
201- "Stopped all servers\n " ,
202- "run command should have returned the correct output" )
203-
204- waitGroup .Done ()
205- }(& waitGroup )
206-
207253 waitGroup .Wait ()
208254
209255 // Clean up.
0 commit comments