-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle case where webhook event may not be set
- Loading branch information
Showing
4 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -499,3 +499,75 @@ func TestProjectsService_UpdateProjectWithWebhook(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestProjectsService_UpdateProjectWithWebhookEventNotSet(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
arg *models.Project | ||
expResult *models.Project | ||
wantError bool | ||
wantErrorMsg string | ||
whResponse []byte | ||
}{ | ||
{ | ||
"success: webhook event ignored", | ||
&models.Project{ | ||
ID: 1, | ||
Name: "my-project", | ||
Administrators: []string{"[email protected]"}, | ||
Readers: nil, | ||
Team: "team-1", | ||
}, | ||
&models.Project{ | ||
ID: 1, | ||
Name: "my-project", | ||
MLFlowTrackingURL: MLFlowTrackingURL, | ||
Administrators: []string{"[email protected]"}, | ||
Readers: nil, | ||
Team: "team-1", | ||
}, | ||
false, | ||
"", | ||
[]byte(`{ | ||
"id": 1, | ||
"name": "my-project", | ||
"mlflow_tracking_url": "http://localhost:5555", | ||
"administrators": ["[email protected]"], | ||
"team": "team-1", | ||
"stream": "team-2-modified-by-webhook" | ||
}`), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
storage := &mocks.ProjectRepository{} | ||
storage.On("Save", tt.expResult).Return(tt.expResult, nil) | ||
|
||
authEnforcer := &enforcerMock.Enforcer{} | ||
mockClient1 := &webhooks.MockWebhookClient{} | ||
mockClient1.On("IsAsync").Return(false) | ||
mockClient1.On("GetName").Return("webhook1") | ||
mockClient1.On("IsFinalResponse").Return(true) | ||
mockClient1.On("GetUseDataFrom").Return("") | ||
mockClient1.On("Invoke", mock.Anything, mock.Anything).Return(tt.whResponse, nil) | ||
whManager := &webhooks.SimpleWebhookManager{ | ||
SyncClients: map[webhooks.EventType][]webhooks.WebhookClient{ | ||
ProjectCreatedEvent: { | ||
mockClient1, | ||
}, | ||
}, | ||
} | ||
mockClient1.On("Invoke", mock.Anything, mock.Anything).Return(tt.whResponse, nil) | ||
projectsService, err := NewProjectsService(MLFlowTrackingURL, storage, authEnforcer, false, whManager) | ||
|
||
assert.NoError(t, err) | ||
|
||
res, err := projectsService.UpdateProject(context.Background(), tt.arg) | ||
require.NoError(t, err) | ||
require.Equal(t, tt.expResult, res) | ||
|
||
storage.AssertExpectations(t) | ||
authEnforcer.AssertExpectations(t) | ||
}) | ||
} | ||
} |