diff --git a/Dockerfile b/Dockerfile index b3cd263df3bfaf8e3073a3165daa340abd5e5722..bedb4262097879c2f2429853929755dd84e52b70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # NOTE: USING THIS IMAGE UNTIL registry1 credentials are added to IL2 runners # Build the manager binary -FROM registry.il2.dso.mil/platform-one/devops/pipeline-templates/pipeline-job/golang-builder-1.6:1.0 as builder +FROM registry.il2.dso.mil/platform-one/devops/pipeline-templates/valkyrie/golang-builder-1.6:1.0 as builder WORKDIR /workspace # Copy the Go Modules manifests diff --git a/clients/gitlab/client.go b/clients/gitlab/client.go index 26fd3526924f8f018eb5dd826c5587fdbd38df2f..45e7cd945e4993ac43b9e320edd275e8cdf1dd72 100644 --- a/clients/gitlab/client.go +++ b/clients/gitlab/client.go @@ -264,9 +264,10 @@ func (r Client) DeleteUser(userID int, waitInterval int, waitCount int) (int, er } // DeleteUserByUsername - convenience method -func (r Client) DeleteUserByUsername(username string) (int, error) { - // expect return status code of http.StatusNoContent 204 or http.StatusNotFound 404 - logPrefix := "Completed call to DeleteUserByUsername." +func (r Client) DeleteUserByUsername(username string, waitInterval int, waitCount int) (int, error) { + // waiting will be skilled if waitCount is 0 + // setting wait will use a loop to wait until resource has completed deletion + logPrefix := "DeleteUserByUsername" var opts = gogitlab.ListUsersOptions{Username: &username} @@ -283,7 +284,7 @@ func (r Client) DeleteUserByUsername(username string) (int, error) { return statusCode, nil } - statusCode, err := r.DeleteUser(users[0].ID, 0, 0) + statusCode, err := r.DeleteUser(users[0].ID, waitInterval, waitCount) if err != nil { processError(logPrefix, err) @@ -643,7 +644,7 @@ func (r Client) AddProject(createProjectOptions gogitlab.CreateProjectOptions, g } newProject, res, err := r.client.Projects.CreateProject(&opts) - + if err != nil { processError(logPrefix, err) return nil, 0, err @@ -695,7 +696,7 @@ func (r Client) DeleteProject(projectID int, waitInterval int, waitCount int) (i if waitCount > 0 { done := false retryCount := waitCount - + for !done && retryCount > 0 { _, res, err = r.client.Projects.GetProject(projectID, &opts) if err != nil && res == nil { diff --git a/clients/gitlab/client_test.go b/clients/gitlab/client_test.go index bdb96d73a8b977bf27a773d677789edb1eeb7b59..c37374f6bd0e9630b58a31f09b84b6d736928e13 100644 --- a/clients/gitlab/client_test.go +++ b/clients/gitlab/client_test.go @@ -236,7 +236,7 @@ func TestClient_AddUser(t *testing.T) { apiURL string } type args struct { - createUserOptions *gogitlab.CreateUserOptions + createUserOptions *gogitlab.CreateUserOptions } tests := []struct { name string @@ -350,6 +350,8 @@ func TestClient_DeleteUser(t *testing.T) { testUserID := 1 testUsername := "testusername" testUser := gogitlab.User{ID: testUserID, Username: testUsername} + testUserArray := []*gogitlab.User{} + testUserArray = append(testUserArray, &testUser) counter := 0 httpmock.RegisterResponder("DELETE", @@ -364,9 +366,9 @@ func TestClient_DeleteUser(t *testing.T) { func(req *http.Request) (*http.Response, error) { counter = counter + 1 if counter%4 == 0 { - return httpmock.NewJsonResponse(404, testUser) + return httpmock.NewJsonResponse(404, testUserArray) } - return httpmock.NewJsonResponse(202, testUser) + return httpmock.NewJsonResponse(202, testUserArray) }, ) @@ -406,7 +408,7 @@ func TestClient_DeleteUser(t *testing.T) { token: tt.fields.token, apiURL: tt.fields.apiURL, } - got, err := r.DeleteUser(tt.args.userID) + got, err := r.DeleteUser(tt.args.userID, 1000, 10) if (err != nil) != tt.wantErr { t.Errorf("Client.DeleteUser() error = %v, wantErr %v", err, tt.wantErr) return @@ -430,13 +432,24 @@ func TestClient_DeleteUserByUsername(t *testing.T) { testUserArray := []*gogitlab.User{} testUserArray = append(testUserArray, &testUser) + counter := 0 httpmock.RegisterResponder("DELETE", `=~^https://test/api/v4/users.*`, - httpmock.NewJsonResponderOrPanic(202, testUser), + func(req *http.Request) (*http.Response, error) { + return httpmock.NewJsonResponse(201, testUser) + }, ) + + // setup a mock that will change response on every 4th call httpmock.RegisterResponder("GET", `=~^https://test/api/v4/users.*`, - httpmock.NewJsonResponderOrPanic(200, testUserArray), + func(req *http.Request) (*http.Response, error) { + counter = counter + 1 + if counter%4 == 0 { + return httpmock.NewJsonResponse(404, testUserArray) + } + return httpmock.NewJsonResponse(202, testUserArray) + }, ) // test objects @@ -462,10 +475,10 @@ func TestClient_DeleteUserByUsername(t *testing.T) { wantErr bool }{ { - name: "DeleteUser 1", + name: "DeleteUserByUsername 1", fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, args: args{username: testUsername}, - want: 202, + want: 200, wantErr: false, }, } @@ -476,7 +489,7 @@ func TestClient_DeleteUserByUsername(t *testing.T) { token: tt.fields.token, apiURL: tt.fields.apiURL, } - got, err := r.DeleteUserByUsername(tt.args.username) + got, err := r.DeleteUserByUsername(tt.args.username, 1000, 10) if (err != nil) != tt.wantErr { t.Errorf("Client.DeleteUserByUsername() error = %v, wantErr %v", err, tt.wantErr) return @@ -718,8 +731,13 @@ func TestClient_DeleteGroup(t *testing.T) { ) httpmock.RegisterResponder("GET", `=~^https://test/api/v4/groups.*`, - httpmock.NewJsonResponderOrPanic(200, testGroupArray), - ) + func(req *http.Request) (*http.Response, error) { + counter = counter + 1 + if counter%4 == 0 { + return httpmock.NewJsonResponse(404, testGroup1) + } + return httpmock.NewJsonResponse(202, testGroup1) + }) // test objects testGroupID := 1 @@ -758,7 +776,7 @@ func TestClient_DeleteGroup(t *testing.T) { token: tt.fields.token, apiURL: tt.fields.apiURL, } - got, err := r.DeleteGroup(tt.args.groupID) + got, err := r.DeleteGroup(tt.args.groupID, 1000, 10) if (err != nil) != tt.wantErr { t.Errorf("Client.DeleteGroup() error = %v, wantErr %v", err, tt.wantErr) return @@ -941,7 +959,7 @@ func TestClient_AddProject(t *testing.T) { } type args struct { createProjectOptions *gogitlab.CreateProjectOptions - groupID int + groupID int } tests := []struct { name string diff --git a/controllers/gitlab/mocks_test.go b/controllers/gitlab/mocks_test.go index bde2409714d2981413e818021f9b6f6399f71b04..358bf605e70956ab9e91246212b5b764aeabed60 100755 --- a/controllers/gitlab/mocks_test.go +++ b/controllers/gitlab/mocks_test.go @@ -98,11 +98,11 @@ func (m *MockClient) DeleteAllOf(ctx context.Context, obj client.Object, opts .. } type MockStatusWriter struct { - updateFunction func(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error + updateFunction func(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error updateFunctionCalled bool - patchFunction func(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error - updatedObject client.Object - updatedOptions []client.UpdateOption + patchFunction func(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error + updatedObject client.Object + updatedOptions []client.UpdateOption } func (m *MockStatusWriter) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error { diff --git a/controllers/gitlab/project_controller.go b/controllers/gitlab/project_controller.go index aa0974e37d3ba8e162f71b073c4dbb155bd9214e..d67ea4c26f9ab9be87299b2d03ef98553e2f6a37 100644 --- a/controllers/gitlab/project_controller.go +++ b/controllers/gitlab/project_controller.go @@ -40,9 +40,9 @@ type ProjectReconciler struct { // errors const ( - errorWhileLookingUpProject string = "error while looking up project" - errorGettingGroupFromGitlab string = "Error while getting Group from Gitlab." - errorUpdatingStatusOfProject = "Error updating status of project" + errorWhileLookingUpProject string = "error while looking up project" + errorGettingGroupFromGitlab string = "Error while getting Group from Gitlab." + errorUpdatingStatusOfProject = "Error updating status of project" ) // statuses diff --git a/controllers/gitlab/project_controller_test.go b/controllers/gitlab/project_controller_test.go index 0668288f23a36c0de4b263068ab31dc3a0b5088a..975132961bdc73719c2c4dbf5e68ca265873d57d 100644 --- a/controllers/gitlab/project_controller_test.go +++ b/controllers/gitlab/project_controller_test.go @@ -53,7 +53,7 @@ func getControllerWithMocksInGreenTestState() (ProjectReconciler, *MockManager, Language: "golang", }, Status: gitlabv1alpha1.ProjectStatus{ - URL: "", + URL: "", State: "", }, } diff --git a/rlog.conf b/rlog.conf index 725cd1f824b7018f2118af8c164ea1622c163333..3af4f5c496ac6fc64f5df2766ecfc5103b59c1c0 100644 --- a/rlog.conf +++ b/rlog.conf @@ -1,8 +1,9 @@ # Comment lines start with a '#' +# any variable can be prefixed with ! to prevent override by ENV variables # export RLOG_CONF_FILE= RLOG_LOG_LEVEL = DEBUG RLOG_LOG_STREAM = stdout -# time format - use ! to prevent override by environment variable +# time format - RLOG_TIME_FORMAT="2006/01/06 15:04:05.00" # RLOG_TIME_FORMAT= UnixDate # optional list caller information