Skip to content

Commit

Permalink
Fixed unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
satr committed Dec 27, 2023
1 parent 3849a95 commit 4e1c325
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/applications/applications_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions api/environmentvariables/env_vars_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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).
Expand All @@ -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()

Expand All @@ -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)

Expand All @@ -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)

Expand Down
16 changes: 8 additions & 8 deletions api/secrets/secret_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 4e1c325

Please sign in to comment.