From 4e1c32542d735942c735e68b8a6d2e06ee80034d Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Wed, 27 Dec 2023 13:18:07 +0100 Subject: [PATCH] Fixed unit-tests --- api/applications/applications_controller_test.go | 2 +- .../env_vars_controller_test.go | 14 +++++++------- api/secrets/secret_controller_test.go | 16 ++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/api/applications/applications_controller_test.go b/api/applications/applications_controller_test.go index 9d040e5f..085422a6 100644 --- a/api/applications/applications_controller_test.go +++ b/api/applications/applications_controller_test.go @@ -1453,7 +1453,7 @@ func TestModifyApplication_UpdateADGroupValidation(t *testing.T) { for _, ts := range scenarios { t.Run(ts.name, func(t *testing.T) { - _, controllerTestUtils, _, radixClient, _, _ := setupTestWithFactory(nil, newTestApplicationHandlerFactory( + _, controllerTestUtils, _, radixClient, _, _ := setupTestWithFactory(t, newTestApplicationHandlerFactory( ApplicationHandlerConfig{RequireAppConfigurationItem: true, RequireAppADGroups: ts.requireAppADGroups}, func(ctx context.Context, kubeClient kubernetes.Interface, namespace string, configMapName string) (bool, error) { return ts.hasAccessToAdGroups, nil diff --git a/api/environmentvariables/env_vars_controller_test.go b/api/environmentvariables/env_vars_controller_test.go index 3d9e6ac6..89fea9bd 100644 --- a/api/environmentvariables/env_vars_controller_test.go +++ b/api/environmentvariables/env_vars_controller_test.go @@ -32,8 +32,8 @@ const ( subscriptionId = "12347718-c8f8-4995-bfbb-02655ff1f89c" ) -func setupTestWithMockHandler(mockCtrl *gomock.Controller) (*commontest.Utils, *controllertest.Utils, kubernetes.Interface, radixclient.Interface, prometheusclient.Interface, *MockEnvVarsHandler) { - kubeclient, radixclient, prometheusclient, commonTestUtils, _, secretproviderclient := setupTest(nil) +func setupTestWithMockHandler(t *testing.T, mockCtrl *gomock.Controller) (*commontest.Utils, *controllertest.Utils, kubernetes.Interface, radixclient.Interface, prometheusclient.Interface, *MockEnvVarsHandler) { + kubeclient, radixclient, prometheusclient, commonTestUtils, _, secretproviderclient := setupTest(t) handler := NewMockEnvVarsHandler(mockCtrl) handlerFactory := NewMockenvVarsHandlerFactory(mockCtrl) @@ -66,7 +66,7 @@ func Test_GetComponentEnvVars(t *testing.T) { url := fmt.Sprintf("/api/v1/applications/%s/environments/%s/components/%s/envvars", appName, environmentName, componentName) t.Run("Return env-vars", func(t *testing.T) { - commonTestUtils, controllerTestUtils, _, _, _, handler := setupTestWithMockHandler(mockCtrl) + commonTestUtils, controllerTestUtils, _, _, _, handler := setupTestWithMockHandler(t, mockCtrl) _, err := setupDeployment(commonTestUtils, appName, environmentName, componentName, nil) require.NoError(t, err) handler.EXPECT().GetComponentEnvVars(appName, environmentName, componentName). @@ -109,7 +109,7 @@ func Test_GetComponentEnvVars(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() - commonTestUtils, controllerTestUtils, _, _, _, handler := setupTestWithMockHandler(mockCtrl) + commonTestUtils, controllerTestUtils, _, _, _, handler := setupTestWithMockHandler(t, mockCtrl) _, err := setupDeployment(commonTestUtils, appName, environmentName, componentName, nil) require.NoError(t, err) handler.EXPECT().GetComponentEnvVars(appName, environmentName, componentName). @@ -130,7 +130,7 @@ func Test_GetComponentEnvVars(t *testing.T) { } func Test_ChangeEnvVar(t *testing.T) { - // setupTestWithMockHandler() + // setupTestWithMockHandler(t, ) ctrl := gomock.NewController(t) defer ctrl.Finish() @@ -150,7 +150,7 @@ func Test_ChangeEnvVar(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() - commonTestUtils, controllerTestUtils, _, _, _, handler := setupTestWithMockHandler(mockCtrl) + commonTestUtils, controllerTestUtils, _, _, _, handler := setupTestWithMockHandler(t, mockCtrl) _, err := setupDeployment(commonTestUtils, appName, environmentName, componentName, nil) require.NoError(t, err) @@ -168,7 +168,7 @@ func Test_ChangeEnvVar(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() - commonTestUtils, controllerTestUtils, _, _, _, handler := setupTestWithMockHandler(mockCtrl) + commonTestUtils, controllerTestUtils, _, _, _, handler := setupTestWithMockHandler(t, mockCtrl) _, err := setupDeployment(commonTestUtils, appName, environmentName, componentName, nil) require.NoError(t, err) diff --git a/api/secrets/secret_controller_test.go b/api/secrets/secret_controller_test.go index e6567478..13cd2f9c 100644 --- a/api/secrets/secret_controller_test.go +++ b/api/secrets/secret_controller_test.go @@ -65,8 +65,8 @@ func executeUpdateComponentSecretTest(t *testing.T, oldSecretValue, updateSecret configureApplicationComponentSecret) } -func executeUpdateJobSecretTest(oldSecretValue, updateSecret, updateComponent, updateSecretName, updateSecretValue string) (*httptest.ResponseRecorder, error) { - return executeUpdateSecretTest(nil, oldSecretValue, updateSecret, updateComponent, updateSecretName, updateSecretValue, configureApplicationJobSecret) +func executeUpdateJobSecretTest(t *testing.T, oldSecretValue, updateSecret, updateComponent, updateSecretName, updateSecretValue string) (*httptest.ResponseRecorder, error) { + return executeUpdateSecretTest(t, oldSecretValue, updateSecret, updateComponent, updateSecretName, updateSecretValue, configureApplicationJobSecret) } func configureApplicationComponentSecret(builder *operatorutils.ApplicationBuilder) { @@ -154,7 +154,7 @@ func TestUpdateSecret_OK(t *testing.T) { require.NoError(t, err) assert.Equal(t, http.StatusOK, response.Code) - response, err = executeUpdateJobSecretTest(oldSecretValue, anyEnvironment, anyJobName, anyEnvironmentName, updateSecretValue) + response, err = executeUpdateJobSecretTest(t, oldSecretValue, anyEnvironment, anyJobName, anyEnvironmentName, updateSecretValue) require.NoError(t, err) assert.Equal(t, http.StatusOK, response.Code) } @@ -168,7 +168,7 @@ func TestUpdateSecret_NonExistingEnvironment_Missing2(t *testing.T) { require.NoError(t, err) assert.Equal(t, http.StatusOK, response.Code) - response, err = executeUpdateJobSecretTest(oldSecretValue, anyEnvironment, anyJobName, nonExistingSecretName, updateSecretValue) + response, err = executeUpdateJobSecretTest(t, oldSecretValue, anyEnvironment, anyJobName, nonExistingSecretName, updateSecretValue) require.NoError(t, err) assert.Equal(t, http.StatusOK, response.Code) } @@ -184,7 +184,7 @@ func TestUpdateSecret_EmptySecretValue_ValidationError(t *testing.T) { assert.Equal(t, "New secret value is empty", errorResponse.Message) assert.Equal(t, "Secret failed validation", errorResponse.Err.Error()) - response, err = executeUpdateJobSecretTest(oldSecretValue, anyEnvironment, anyJobName, anyEnvironmentName, updateSecretValue) + response, err = executeUpdateJobSecretTest(t, oldSecretValue, anyEnvironment, anyJobName, anyEnvironmentName, updateSecretValue) require.NoError(t, err) errorResponse, _ = controllertest.GetErrorResponse(response) assert.Equal(t, http.StatusBadRequest, response.Code) @@ -200,7 +200,7 @@ func TestUpdateSecret_NoUpdate_NoError(t *testing.T) { require.NoError(t, err) assert.Equal(t, http.StatusOK, response.Code) - response, err = executeUpdateJobSecretTest(oldSecretValue, anyEnvironment, anyJobName, anyEnvironmentName, updateSecretValue) + response, err = executeUpdateJobSecretTest(t, oldSecretValue, anyEnvironment, anyJobName, anyEnvironmentName, updateSecretValue) require.NoError(t, err) assert.Equal(t, http.StatusOK, response.Code) } @@ -217,7 +217,7 @@ func TestUpdateSecret_NonExistingComponent_Missing(t *testing.T) { assert.Equal(t, http.StatusNotFound, response.Code) assert.Equal(t, fmt.Sprintf("secrets \"%s\" not found", nonExistingSecretObjName), errorResponse.Err.Error()) - response, err = executeUpdateJobSecretTest(oldSecretValue, anyEnvironment, nonExistingComponent, anyEnvironmentName, updateSecretValue) + response, err = executeUpdateJobSecretTest(t, oldSecretValue, anyEnvironment, nonExistingComponent, anyEnvironmentName, updateSecretValue) require.NoError(t, err) errorResponse, _ = controllertest.GetErrorResponse(response) assert.Equal(t, http.StatusNotFound, response.Code) @@ -236,7 +236,7 @@ func TestUpdateSecret_NonExistingEnvironment_Missing(t *testing.T) { assert.Equal(t, http.StatusNotFound, response.Code) assert.Equal(t, fmt.Sprintf("secrets \"%s\" not found", secretObjName), errorResponse.Err.Error()) - response, err = executeUpdateJobSecretTest(oldSecretValue, nonExistingSecret, anyJobName, anyEnvironmentName, updateSecretValue) + response, err = executeUpdateJobSecretTest(t, oldSecretValue, nonExistingSecret, anyJobName, anyEnvironmentName, updateSecretValue) require.NoError(t, err) errorResponse, _ = controllertest.GetErrorResponse(response) secretObjName = operatorutils.GetComponentSecretName(anyJobName)