We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stakwork Run
File: routes/ticket_routes.go
package integrationtests import ( "context" "encoding/json" "errors" "net/http" "net/http/httptest" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) // Mock dependencies type MockDB struct { mock.Mock } func (m *MockDB) GetWorkspaceByUuid(uuid string) *Workspace { args := m.Called(uuid) return args.Get(0).(*Workspace) } func (m *MockDB) ProcessDeleteWorkspace(uuid string) error { args := m.Called(uuid) return args.Error(0) } type Workspace struct { OwnerPubKey string } type MockLogger struct { mock.Mock } func (m *MockLogger) Info(format string, v ...interface{}) { m.Called(format, v) } func (m *MockLogger) Error(format string, v ...interface{}) { m.Called(format, v) } // Test cases func TestSuccessfulWorkspaceDeletion(t *testing.T) { // Setup db := new(MockDB) logger := new(MockLogger) handler := &workspaceHandler{db: db, logger: logger} workspace := &Workspace{OwnerPubKey: "validPubKey"} db.On("GetWorkspaceByUuid", "valid-uuid").Return(workspace) db.On("ProcessDeleteWorkspace", "valid-uuid").Return(nil) req := httptest.NewRequest("DELETE", "/workspaces/delete/valid-uuid", nil) req = req.WithContext(context.WithValue(req.Context(), "authKey", "validPubKey")) w := httptest.NewRecorder() // Execute handler.DeleteWorkspace(w, req) // Assert assert.Equal(t, http.StatusOK, w.Code) var response Workspace json.NewDecoder(w.Body).Decode(&response) assert.Equal(t, workspace, &response) } func TestUnauthorizedWorkspaceDeletionAttempt(t *testing.T) { // Setup db := new(MockDB) logger := new(MockLogger) handler := &workspaceHandler{db: db, logger: logger} workspace := &Workspace{OwnerPubKey: "validPubKey"} db.On("GetWorkspaceByUuid", "valid-uuid").Return(workspace) req := httptest.NewRequest("DELETE", "/workspaces/delete/valid-uuid", nil) req = req.WithContext(context.WithValue(req.Context(), "authKey", "invalidPubKey")) w := httptest.NewRecorder() // Execute handler.DeleteWorkspace(w, req) // Assert assert.Equal(t, http.StatusUnauthorized, w.Code) } func TestInvalidUUIDFormat(t *testing.T) { // Setup handler := &workspaceHandler{} req := httptest.NewRequest("DELETE", "/workspaces/delete/invalid-uuid-format", nil) w := httptest.NewRecorder() // Execute handler.DeleteWorkspace(w, req) // Assert assert.Equal(t, http.StatusBadRequest, w.Code) } func TestNonExistentWorkspaceUUID(t *testing.T) { // Setup db := new(MockDB) logger := new(MockLogger) handler := &workspaceHandler{db: db, logger: logger} db.On("GetWorkspaceByUuid", "non-existent-uuid").Return(nil) req := httptest.NewRequest("DELETE", "/workspaces/delete/non-existent-uuid", nil) req = req.WithContext(context.WithValue(req.Context(), "authKey", "validPubKey")) w := httptest.NewRecorder() // Execute handler.DeleteWorkspace(w, req) // Assert assert.Equal(t, http.StatusNotFound, w.Code) } func TestDatabaseUnavailability(t *testing.T) { // Setup db := new(MockDB) logger := new(MockLogger) handler := &workspaceHandler{db: db, logger: logger} workspace := &Workspace{OwnerPubKey: "validPubKey"} db.On("GetWorkspaceByUuid", "valid-uuid").Return(workspace) db.On("ProcessDeleteWorkspace", "valid-uuid").Return(errors.New("database error")) req := httptest.NewRequest("DELETE", "/workspaces/delete/valid-uuid", nil) req = req.WithContext(context.WithValue(req.Context(), "authKey", "validPubKey")) w := httptest.NewRecorder() // Execute handler.DeleteWorkspace(w, req) // Assert assert.Equal(t, http.StatusInternalServerError, w.Code) } func TestConcurrentDeletionRequests(t *testing.T) { // Setup db := new(MockDB) logger := new(MockLogger) handler := &workspaceHandler{db: db, logger: logger} workspace := &Workspace{OwnerPubKey: "validPubKey"} db.On("GetWorkspaceByUuid", "valid-uuid").Return(workspace) db.On("ProcessDeleteWorkspace", "valid-uuid").Return(nil) req := httptest.NewRequest("DELETE", "/workspaces/delete/valid-uuid", nil) req = req.WithContext(context.WithValue(req.Context(), "authKey", "validPubKey")) // Simulate concurrent requests w1 := httptest.NewRecorder() w2 := httptest.NewRecorder() go handler.DeleteWorkspace(w1, req) go handler.DeleteWorkspace(w2, req) // Assert assert.Equal(t, http.StatusOK, w1.Code) assert.Contains(t, []int{http.StatusOK, http.StatusNotFound, http.StatusConflict}, w2.Code) }
The text was updated successfully, but these errors were encountered:
@tomsmith8 please assign
Sorry, something went wrong.
@tomsmith8 assign me?/
@elraphty can you review this ticket please
elraphty
No branches or pull requests
Integration Test Coverage for "/workspaces/delete/{uuid}"
Stakwork Run
Integration Test Code
File: routes/ticket_routes.go
The text was updated successfully, but these errors were encountered: