@@ -10,6 +10,8 @@ import (
1010 "fmt"
1111 "net"
1212 "net/http"
13+ "os"
14+ "sort"
1315 "testing"
1416 "time"
1517
@@ -41,17 +43,21 @@ func TestSuite(t *testing.T) {
4143 suite .Run (t , new (AuxiliaryTestSuite ))
4244}
4345
44- func (s * AuxiliaryTestSuite ) TestAuxiliary_Connection () {
46+ func (s * AuxiliaryTestSuite ) TestAuxiliary_Test1_Connection () {
4547 s .instanceID = utils .VerifyConnection (s .T (), 2 , utils .MockManagementPlaneAPIAddress )
4648 s .False (s .T ().Failed ())
4749 utils .VerifyUpdateDataPlaneHealth (s .T (), utils .MockManagementPlaneAPIAddress )
4850
4951 utils .VerifyConnection (s .T (), 2 , utils .AuxiliaryMockManagementPlaneAPIAddress )
5052 s .False (s .T ().Failed ())
5153 utils .VerifyUpdateDataPlaneHealth (s .T (), utils .AuxiliaryMockManagementPlaneAPIAddress )
54+
55+ commandResponses := utils .ManagementPlaneResponses (s .T (), 1 , utils .MockManagementPlaneAPIAddress )
56+ s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , commandResponses [0 ].GetCommandResponse ().GetStatus ())
57+ s .Equal ("Successfully updated all files" , commandResponses [0 ].GetCommandResponse ().GetMessage ())
5258}
5359
54- func (s * AuxiliaryTestSuite ) TestAuxiliary_Reconnection () {
60+ func (s * AuxiliaryTestSuite ) TestAuxiliary_Test2_Reconnection () {
5561 ctx := context .Background ()
5662 timeout := 15 * time .Second
5763
@@ -76,7 +82,7 @@ func (s *AuxiliaryTestSuite) TestAuxiliary_Reconnection() {
7682 s .Equal (originalID , currentID )
7783}
7884
79- func (s * AuxiliaryTestSuite ) TestAuxiliary_DataplaneHealthRequest () {
85+ func (s * AuxiliaryTestSuite ) TestAuxiliary_Test3_DataplaneHealthRequest () {
8086 utils .ClearManagementPlaneResponses (s .T (), utils .MockManagementPlaneAPIAddress )
8187 utils .ClearManagementPlaneResponses (s .T (), utils .AuxiliaryMockManagementPlaneAPIAddress )
8288
@@ -105,12 +111,12 @@ func (s *AuxiliaryTestSuite) TestAuxiliary_DataplaneHealthRequest() {
105111 s .Equal ("Successfully sent health status update" , commandResponses [0 ].GetCommandResponse ().GetMessage ())
106112 s .False (s .T ().Failed ())
107113
108- // Check auxiliary server still only has 1 ManagementPlaneResponses as it didn't sent the request
114+ // Check auxiliary server still only has 1 ManagementPlaneResponses as it didn't send the request
109115 utils .ManagementPlaneResponses (s .T (), 0 , utils .AuxiliaryMockManagementPlaneAPIAddress )
110116 s .False (s .T ().Failed ())
111117}
112118
113- func (s * AuxiliaryTestSuite ) TestAuxiliary_FileWatcher () {
119+ func (s * AuxiliaryTestSuite ) TestAuxiliary_Test4_FileWatcher () {
114120 // Clear any previous responses from previous tests
115121 utils .ClearManagementPlaneResponses (s .T (), utils .MockManagementPlaneAPIAddress )
116122 utils .ClearManagementPlaneResponses (s .T (), utils .AuxiliaryMockManagementPlaneAPIAddress )
@@ -135,59 +141,66 @@ func (s *AuxiliaryTestSuite) TestAuxiliary_FileWatcher() {
135141 s .Equal ("Successfully updated all files" , auxResponses [0 ].GetCommandResponse ().GetMessage ())
136142}
137143
138- // func (s *AuxiliaryTestSuite) TestAuxiliary_ConfigApply() {
139- // s.instanceID = utils.VerifyConnection(s.T(), 2, utils.MockManagementPlaneAPIAddress)
140- // // Perform config apply
141- // // Check new config is in both Mocks
142- // // Check using hash with new API endpoint which was added to get the file overview
143- // utils.ClearManagementPlaneResponses(s.T(), utils.MockManagementPlaneAPIAddress)
144- // utils.ClearManagementPlaneResponses(s.T(), utils.AuxiliaryMockManagementPlaneAPIAddress)
145- //
146- // ctx := context.Background()
147- //
148- // newConfigFile := "../../config/nginx/nginx-with-test-location.conf"
149- //
150- // if os.Getenv("IMAGE_PATH") == "/nginx-plus/agent" {
151- // newConfigFile = "../../config/nginx/nginx-plus-with-test-location.conf"
152- // }
153- //
154- // err := utils.MockManagementPlaneGrpcContainer.CopyFileToContainer(
155- // ctx,
156- // newConfigFile,
157- // fmt.Sprintf("/mock-management-plane-grpc/config/%s/etc/nginx/nginx.conf", s.instanceID),
158- // 0o666,
159- // )
160- //
161- // require.NoError(s.T(), err)
162- //
163- // utils.PerformConfigApply(s.T(), s.instanceID, utils.MockManagementPlaneAPIAddress)
164- //
165- // commandResponses := utils.ManagementPlaneResponses(s.T(), 2, utils.MockManagementPlaneAPIAddress)
166- //
167- // sort.Slice(commandResponses, func(i, j int) bool {
168- // return commandResponses[i].GetCommandResponse().GetMessage() <
169- // commandResponses[j].GetCommandResponse().GetMessage()
170- // })
171- //
172- // assert.Equal(s.T(), mpi.CommandResponse_COMMAND_STATUS_OK, commandResponses[0].GetCommandResponse().GetStatus())
173- // assert.Equal(s.T(), "Config apply successful", commandResponses[0].GetCommandResponse().GetMessage())
174- // assert.Equal(s.T(), mpi.CommandResponse_COMMAND_STATUS_OK, commandResponses[1].GetCommandResponse().GetStatus())
175- // assert.Equal(s.T(), "Successfully updated all files", commandResponses[1].GetCommandResponse().GetMessage())
176- //
177- // auxResponses := utils.ManagementPlaneResponses(s.T(), 1, utils.AuxiliaryMockManagementPlaneAPIAddress)
178- // assert.Equal(s.T(), mpi.CommandResponse_COMMAND_STATUS_OK, auxResponses[1].GetCommandResponse().GetStatus())
179- // assert.Equal(s.T(), "Successfully updated all files", auxResponses[1].GetCommandResponse().GetMessage())
180- //
181- // overview := utils.CurrentFileOverview(s.T(), s.instanceID, utils.MockManagementPlaneAPIAddress)
182- // overview2 := utils.CurrentFileOverview(s.T(), s.instanceID, utils.AuxiliaryMockManagementPlaneAPIAddress)
183- // s.T().Logf("Overview: %v", overview.ConfigVersion)
184- // s.T().Logf("Overview 2: %v", overview2.ConfigVersion)
185- // }
144+ func (s * AuxiliaryTestSuite ) TestAuxiliary_Test5_ConfigApply () {
145+ utils .ClearManagementPlaneResponses (s .T (), utils .MockManagementPlaneAPIAddress )
146+ utils .ClearManagementPlaneResponses (s .T (), utils .AuxiliaryMockManagementPlaneAPIAddress )
186147
187- //
188- // func (s *AuxiliaryTestSuite) TestAuxiliary_ConfigApplyInvalid() {
189- // // Perform config apply with aux
190- // // Check new config is broken
191- // // Check using hash with new API endpoint which was added to get the file overview
192- //
193- // }
148+ ctx := context .Background ()
149+
150+ newConfigFile := "../../config/nginx/nginx-with-test-location.conf"
151+
152+ if os .Getenv ("IMAGE_PATH" ) == "/nginx-plus/agent" {
153+ newConfigFile = "../../config/nginx/nginx-plus-with-test-location.conf"
154+ }
155+
156+ err := utils .MockManagementPlaneGrpcContainer .CopyFileToContainer (
157+ ctx ,
158+ newConfigFile ,
159+ fmt .Sprintf ("/mock-management-plane-grpc/config/%s/etc/nginx/nginx.conf" , s .instanceID ),
160+ 0o666 ,
161+ )
162+
163+ s .Require ().NoError (err )
164+
165+ utils .PerformConfigApply (s .T (), s .instanceID , utils .MockManagementPlaneAPIAddress )
166+
167+ commandResponses := utils .ManagementPlaneResponses (s .T (), 2 , utils .MockManagementPlaneAPIAddress )
168+
169+ sort .Slice (commandResponses , func (i , j int ) bool {
170+ return commandResponses [i ].GetCommandResponse ().GetMessage () <
171+ commandResponses [j ].GetCommandResponse ().GetMessage ()
172+ })
173+
174+ s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , commandResponses [0 ].GetCommandResponse ().GetStatus ())
175+ s .Equal ("Config apply successful" , commandResponses [0 ].GetCommandResponse ().GetMessage ())
176+ s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , commandResponses [1 ].GetCommandResponse ().GetStatus ())
177+ s .Equal ("Successfully updated all files" , commandResponses [1 ].GetCommandResponse ().GetMessage ())
178+
179+ auxResponses := utils .ManagementPlaneResponses (s .T (), 1 , utils .AuxiliaryMockManagementPlaneAPIAddress )
180+ s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , auxResponses [0 ].GetCommandResponse ().GetStatus ())
181+ s .Equal ("Successfully updated all files" , auxResponses [0 ].GetCommandResponse ().GetMessage ())
182+
183+ // Check the config version is the same in both command and auxiliary servers
184+ commandOverview := utils .CurrentFileOverview (s .T (), s .instanceID , utils .MockManagementPlaneAPIAddress )
185+ auxOverview := utils .CurrentFileOverview (s .T (), s .instanceID , utils .AuxiliaryMockManagementPlaneAPIAddress )
186+ s .Equal (commandOverview .GetConfigVersion (), auxOverview .GetConfigVersion ())
187+ }
188+
189+ func (s * AuxiliaryTestSuite ) TestAuxiliary_Test6_ConfigApplyInvalid () {
190+ // Perform config apply with aux
191+ // Check new config is broken
192+ // Check using hash with new API endpoint which was added to get the file overview
193+
194+ utils .ClearManagementPlaneResponses (s .T (), utils .MockManagementPlaneAPIAddress )
195+ utils .ClearManagementPlaneResponses (s .T (), utils .AuxiliaryMockManagementPlaneAPIAddress )
196+
197+ utils .PerformConfigApply (s .T (), s .instanceID , utils .AuxiliaryMockManagementPlaneAPIAddress )
198+
199+ commandResponses := utils .ManagementPlaneResponses (s .T (), 1 ,
200+ utils .AuxiliaryMockManagementPlaneAPIAddress )
201+ s .Equal (mpi .CommandResponse_COMMAND_STATUS_FAILURE ,
202+ commandResponses [0 ].GetCommandResponse ().GetStatus ())
203+ s .Equal ("Config apply failed" , commandResponses [0 ].GetCommandResponse ().GetMessage ())
204+ s .Equal ("Unable to process request. Management plane is configured as read only." ,
205+ commandResponses [0 ].GetCommandResponse ().GetError ())
206+ }
0 commit comments