Skip to content

Commit 3ec1ae1

Browse files
committed
refactor and rename test suites
1 parent 40e44d0 commit 3ec1ae1

File tree

4 files changed

+32
-42
lines changed

4 files changed

+32
-42
lines changed

test/integration/managementplane/config_apply_test.go

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func (s *ConfigApplyTestSuite) SetupSuite() {
4242
s.teardownTest = utils.SetupConnectionTest(s.T(), false, false, false,
4343
"../../config/agent/nginx-config-with-grpc-client.conf")
4444
s.nginxInstanceID = utils.VerifyConnection(s.T(), 2, utils.MockManagementPlaneAPIAddress)
45+
responses := utils.ManagementPlaneResponses(s.T(), 1, utils.MockManagementPlaneAPIAddress)
46+
s.Require().Equal(mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
47+
s.Require().Equal("Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
4548
}
4649

4750
func (s *ConfigApplyTestSuite) TearDownSuite() {
@@ -52,22 +55,18 @@ func (s *ConfigApplyTestSuite) TearDownTest() {
5255
utils.ClearManagementPlaneResponses(s.T(), utils.MockManagementPlaneAPIAddress)
5356
}
5457

55-
func (s *ConfigApplyTestSuite) TestConfigApply_Test1_TestSetup() {
56-
responses := utils.ManagementPlaneResponses(s.T(), 1, utils.MockManagementPlaneAPIAddress)
57-
s.Require().Equal(mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
58-
s.Require().Equal("Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
59-
}
60-
61-
func (s *ConfigApplyTestSuite) TestConfigApply_Test2_TestNoConfigChanges() {
58+
func (s *ConfigApplyTestSuite) TestConfigApply_Test1_TestNoConfigChanges() {
6259
utils.PerformConfigApply(s.T(), s.nginxInstanceID, utils.MockManagementPlaneAPIAddress)
63-
responses := utils.ManagementPlaneResponses(s.T(), 1, utils.MockManagementPlaneAPIAddress)
60+
responses := utils.ManagementPlaneResponses(s.T(), 2, utils.MockManagementPlaneAPIAddress)
6461
s.T().Logf("Config apply responses: %v", responses)
6562

6663
s.Equal(mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
67-
s.Equal("Config apply successful, no files to change", responses[0].GetCommandResponse().GetMessage())
64+
s.Equal("Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
65+
s.Equal(mpi.CommandResponse_COMMAND_STATUS_OK, responses[1].GetCommandResponse().GetStatus())
66+
s.Equal("Config apply successful, no files to change", responses[1].GetCommandResponse().GetMessage())
6867
}
6968

70-
func (s *ConfigApplyTestSuite) TestConfigApply_Test3_TestValidConfig() {
69+
func (s *ConfigApplyTestSuite) TestConfigApply_Test2_TestValidConfig() {
7170
newConfigFile := "../../config/nginx/nginx-with-test-location.conf"
7271

7372
if os.Getenv("IMAGE_PATH") == "/nginx-plus/agent" {
@@ -95,7 +94,7 @@ func (s *ConfigApplyTestSuite) TestConfigApply_Test3_TestValidConfig() {
9594
s.Equal("Successfully updated all files", responses[1].GetCommandResponse().GetMessage())
9695
}
9796

98-
func (s *ConfigApplyTestSuite) TestConfigApply_Test4_TestInvalidConfig() {
97+
func (s *ConfigApplyTestSuite) TestConfigApply_Test3_TestInvalidConfig() {
9998
err := utils.MockManagementPlaneGrpcContainer.CopyFileToContainer(
10099
s.ctx,
101100
"../../config/nginx/invalid-nginx.conf",
@@ -117,7 +116,7 @@ func (s *ConfigApplyTestSuite) TestConfigApply_Test4_TestInvalidConfig() {
117116
s.Equal(configApplyErrorMessage, responses[1].GetCommandResponse().GetError())
118117
}
119118

120-
func (s *ConfigApplyTestSuite) TestConfigApply_Test5_TestFileNotInAllowedDirectory() {
119+
func (s *ConfigApplyTestSuite) TestConfigApply_Test4_TestFileNotInAllowedDirectory() {
121120
utils.PerformInvalidConfigApply(s.T(), s.nginxInstanceID)
122121

123122
responses := utils.ManagementPlaneResponses(s.T(), 1, utils.MockManagementPlaneAPIAddress)
@@ -131,32 +130,23 @@ func (s *ConfigApplyTestSuite) TestConfigApply_Test5_TestFileNotInAllowedDirecto
131130
)
132131
}
133132

134-
func TestConfigApplyTestSuite(t *testing.T) {
135-
suite.Run(t, new(ConfigApplyTestSuite))
136-
}
137-
138133
func (s *ConfigApplyChunkingTestSuite) SetupSuite() {
139134
s.ctx = context.Background()
140135
s.teardownTest = utils.SetupConnectionTest(s.T(), false, false, false,
141136
"../../config/agent/nginx-config-with-max-file-size.conf")
142137
s.nginxInstanceID = utils.VerifyConnection(s.T(), 2, utils.MockManagementPlaneAPIAddress)
138+
responses := utils.ManagementPlaneResponses(s.T(), 1, utils.MockManagementPlaneAPIAddress)
139+
s.Require().Equal(mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
140+
s.Require().Equal("Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
143141
}
144142

145143
func (s *ConfigApplyChunkingTestSuite) TearDownSuite() {
146144
s.teardownTest(s.T())
147145
}
148146

149-
func (s *ConfigApplyChunkingTestSuite) TearDownTest() {
147+
func (s *ConfigApplyChunkingTestSuite) TestConfigApplyChunking() {
150148
utils.ClearManagementPlaneResponses(s.T(), utils.MockManagementPlaneAPIAddress)
151-
}
152149

153-
func (s *ConfigApplyChunkingTestSuite) TestConfigApplyChunking_Test1_TestSetup() {
154-
responses := utils.ManagementPlaneResponses(s.T(), 1, utils.MockManagementPlaneAPIAddress)
155-
s.Require().Equal(mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
156-
s.Require().Equal("Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
157-
}
158-
159-
func (s *ConfigApplyChunkingTestSuite) TestConfigApplyChunking_Test2_TestChunkedConfigApply() {
160150
newConfigFile := "../../config/nginx/nginx-1mb-file.conf"
161151

162152
err := utils.MockManagementPlaneGrpcContainer.CopyFileToContainer(
@@ -182,6 +172,7 @@ func (s *ConfigApplyChunkingTestSuite) TestConfigApplyChunking_Test2_TestChunked
182172
s.Equal("Successfully updated all files", responses[1].GetCommandResponse().GetMessage())
183173
}
184174

185-
func TestConfigApplyChunkingTestSuite(t *testing.T) {
175+
func TestConfigApplyTestSuite(t *testing.T) {
176+
suite.Run(t, new(ConfigApplyTestSuite))
186177
suite.Run(t, new(ConfigApplyChunkingTestSuite))
187178
}

test/integration/managementplane/config_upload_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,34 @@ import (
1818
"github.com/stretchr/testify/suite"
1919
)
2020

21-
type ConfigUploadMPIFileWatcherTestSuite struct {
21+
type MPITestSuite struct {
2222
suite.Suite
2323
ctx context.Context
2424
teardownTest func(testing.TB)
2525
nginxInstanceID string
2626
}
2727

28-
func (s *ConfigUploadMPIFileWatcherTestSuite) TearDownSuite() {
28+
func (s *MPITestSuite) TearDownSuite() {
2929
s.teardownTest(s.T())
3030
}
3131

32-
func (s *ConfigUploadMPIFileWatcherTestSuite) TearDownTest() {
32+
func (s *MPITestSuite) TearDownTest() {
3333
utils.ClearManagementPlaneResponses(s.T(), utils.MockManagementPlaneAPIAddress)
3434
}
3535

36-
func (s *ConfigUploadMPIFileWatcherTestSuite) SetupSuite() {
36+
func (s *MPITestSuite) SetupSuite() {
3737
s.ctx = context.Background()
3838
s.teardownTest = utils.SetupConnectionTest(s.T(), true, false, false,
3939
"../../config/agent/nginx-config-with-grpc-client.conf")
4040
s.nginxInstanceID = utils.VerifyConnection(s.T(), 2, utils.MockManagementPlaneAPIAddress)
41-
}
42-
43-
func (s *ConfigUploadMPIFileWatcherTestSuite) TestConfigUploadMPTFileWatcher_1_TestSetup() {
4441
responses := utils.ManagementPlaneResponses(s.T(), 1, utils.MockManagementPlaneAPIAddress)
4542
s.Equal(mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
4643
s.Equal("Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
4744

4845
s.False(s.T().Failed())
4946
}
5047

51-
func (s *ConfigUploadMPIFileWatcherTestSuite) TestConfigUploadMPTFileWatcher_TestConfigUpload() {
48+
func (s *MPITestSuite) TestConfigUpload() {
5249
request := fmt.Sprintf(`{
5350
"message_meta": {
5451
"message_id": "5d0fa83e-351c-4009-90cd-1f2acce2d184",
@@ -76,12 +73,14 @@ func (s *ConfigUploadMPIFileWatcherTestSuite) TestConfigUploadMPTFileWatcher_Tes
7673
s.Require().NoError(err)
7774
s.Equal(http.StatusOK, resp.StatusCode())
7875

79-
responses := utils.ManagementPlaneResponses(s.T(), 1, utils.MockManagementPlaneAPIAddress)
76+
responses := utils.ManagementPlaneResponses(s.T(), 2, utils.MockManagementPlaneAPIAddress)
8077

8178
s.Equal(mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
8279
s.Equal("Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
80+
s.Equal(mpi.CommandResponse_COMMAND_STATUS_OK, responses[1].GetCommandResponse().GetStatus())
81+
s.Equal("Successfully updated all files", responses[1].GetCommandResponse().GetMessage())
8382
}
8483

85-
func TestConfigUploadMPIFileWatcherTestSuite(t *testing.T) {
86-
suite.Run(t, new(ConfigUploadMPIFileWatcherTestSuite))
84+
func TestMPITestSuite(t *testing.T) {
85+
suite.Run(t, new(MPITestSuite))
8786
}

test/integration/managementplane/file_watcher_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
1212
)
1313

14-
func (s *ConfigUploadMPIFileWatcherTestSuite) TestFileWatcher_Test1_TestUpdateNGINXConfig() {
14+
func (s *MPITestSuite) TestFileWatcher_Test1_TestUpdateNGINXConfig() {
1515
err := utils.Container.CopyFileToContainer(
1616
s.ctx,
1717
"../../config/nginx/nginx-with-server-block-access-log.conf",
@@ -28,7 +28,7 @@ func (s *ConfigUploadMPIFileWatcherTestSuite) TestFileWatcher_Test1_TestUpdateNG
2828
utils.VerifyUpdateDataPlaneStatus(s.T(), utils.MockManagementPlaneAPIAddress)
2929
}
3030

31-
func (s *ConfigUploadMPIFileWatcherTestSuite) TestFileWatcher_Test2_TestCreateNGINXConfig() {
31+
func (s *MPITestSuite) TestFileWatcher_Test2_TestCreateNGINXConfig() {
3232
err := utils.Container.CopyFileToContainer(
3333
s.ctx,
3434
"../../config/nginx/empty-nginx.conf",
@@ -44,7 +44,7 @@ func (s *ConfigUploadMPIFileWatcherTestSuite) TestFileWatcher_Test2_TestCreateNG
4444
utils.VerifyUpdateDataPlaneStatus(s.T(), utils.MockManagementPlaneAPIAddress)
4545
}
4646

47-
func (s *ConfigUploadMPIFileWatcherTestSuite) TestFileWatcher_Test3_TestDeleteNGINXConfig() {
47+
func (s *MPITestSuite) TestFileWatcher_Test3_TestDeleteNGINXConfig() {
4848
_, _, err := utils.Container.Exec(
4949
s.ctx,
5050
[]string{"rm", "-rf", "/etc/nginx/test"},

test/integration/managementplane/grpc_management_plane_api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ func (s *ConfigApplyTestSuite) TestGrpc_Test1_Reconnection() {
3838
}
3939

4040
// Verify that the agent sends a connection request and an update data plane status request
41-
func (s *ConfigUploadMPIFileWatcherTestSuite) TestGrpc_Test2_StartUp() {
41+
func (s *MPITestSuite) TestGrpc_Test2_StartUp() {
4242
utils.VerifyUpdateDataPlaneHealth(s.T(), utils.MockManagementPlaneAPIAddress)
4343
}
4444

45-
func (s *ConfigUploadMPIFileWatcherTestSuite) TestGrpc_Test3_DataplaneHealthRequest() {
45+
func (s *MPITestSuite) TestGrpc_Test3_DataplaneHealthRequest() {
4646
request := `{
4747
"message_meta": {
4848
"message_id": "5d0fa83e-351c-4009-90cd-1f2acce2d184",

0 commit comments

Comments
 (0)