Skip to content

Commit

Permalink
fix test-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Victor Goklas authored and Jonathan Victor Goklas committed Jun 13, 2024
1 parent 02f36ce commit b7927ca
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
5 changes: 0 additions & 5 deletions api/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ func (s *APITestSuite) SetupTest() {
Mlflow: &config.MlflowConfig{
TrackingURL: "http://mlflow:5000",
},
UpdateProject: &config.UpdateProjectConfig{
Endpoint: "",
PayloadTemplate: "template-payload",
ResponseTemplate: "template-response",
},
DefaultSecretStorage: &config.SecretStorage{
Name: "vault",
Type: string(models.VaultSecretStorageType),
Expand Down
4 changes: 2 additions & 2 deletions api/api/projects_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func (c *ProjectsController) UpdateProject(r *http.Request, vars map[string]stri

if response != nil {
return Ok(response)
} else {
return Ok(project)
}

return Ok(project)
}

func (c *ProjectsController) GetProject(r *http.Request, vars map[string]string, body interface{}) *Response {
Expand Down
6 changes: 4 additions & 2 deletions api/api/projects_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ func TestUpdateProject(t *testing.T) {
Stream: "dsp",
Administrators: []string{adminUser},
},
expectedResponse: nil,
expectedResponse: &Response{
code: 200,
},
expectedMessage: map[string]interface{}{
"status": "success",
"message": "Project updated successfully",
Expand Down Expand Up @@ -605,7 +607,7 @@ func TestUpdateProject(t *testing.T) {

assert.Equal(t, tC.expectedResponse.code, rr.Code)
if tC.expectedResponse.code >= 200 && tC.expectedResponse.code < 300 {
if tC.expectedResponse != nil {
if tC.expectedResponse.data != nil {
project := &models.Project{}
err = json.Unmarshal(rr.Body.Bytes(), &project)
assert.NoError(t, err)
Expand Down
12 changes: 12 additions & 0 deletions api/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func TestLoad(t *testing.T) {
AllowCustomTeam: true,
AllowCustomStream: true,
},
UpdateProject: &config.UpdateProjectConfig{
Endpoint: "",
PayloadTemplate: "",
ResponseTemplate: "",
LabelsBlacklist: nil,
},
DefaultSecretStorage: &config.SecretStorage{
Name: "default-secret-storage",
Type: "vault",
Expand Down Expand Up @@ -149,6 +155,12 @@ func TestLoad(t *testing.T) {
AllowCustomTeam: true,
AllowCustomStream: true,
},
UpdateProject: &config.UpdateProjectConfig{
Endpoint: "",
PayloadTemplate: "",
ResponseTemplate: "",
LabelsBlacklist: nil,
},
DefaultSecretStorage: &config.SecretStorage{
Name: "default-secret-storage",
Type: "vault",
Expand Down
9 changes: 6 additions & 3 deletions api/service/projects_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ func (service *projectsService) UpdateProject(ctx context.Context, project *mode
}

if isLabelBlacklisted(existingProject.Labels, project.Labels, service.updateProjectConfig.LabelsBlacklist) {
return nil, nil, fmt.Errorf("one or more labels are blacklisted or have been removed or changed values and cannot be updated")
return nil, nil,
fmt.Errorf("one or more labels are blacklisted or have been removed or changed values and cannot be updated")
}

if service.webhookManager == nil || !service.webhookManager.IsEventConfigured(ProjectUpdatedEvent) {
Expand Down Expand Up @@ -174,7 +175,8 @@ func (service *projectsService) UpdateProject(ctx context.Context, project *mode
}, webhooks.NoOpErrorHandler)
if err != nil {
return project, nil,
fmt.Errorf("error while invoking %s webhooks or on success callback function, err: %s", ProjectUpdatedEvent, err.Error())
fmt.Errorf("error while invoking %s webhooks or on success callback function, err: %s",
ProjectUpdatedEvent, err.Error())
}

if service.updateProjectConfig.Endpoint != "" {
Expand Down Expand Up @@ -292,7 +294,8 @@ func (service *projectsService) filterAuthorizedProjects(ctx context.Context, pr
return authorizedProjects, nil
}

func (service *projectsService) handleUpdateProjectRequest(project *models.Project) (*models.Project, map[string]interface{}, error) {
func (service *projectsService) handleUpdateProjectRequest(project *models.Project) (*models.Project,
map[string]interface{}, error) {
if service.updateProjectConfig.PayloadTemplate == "" || service.updateProjectConfig.ResponseTemplate == "" {
return project, nil, nil
}
Expand Down

0 comments on commit b7927ca

Please sign in to comment.