mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Update handlers and db
This commit is contained in:
@@ -70,7 +70,7 @@ func setupTestHarness(t *testing.T) *testHarness {
|
||||
|
||||
// Create storage with mock git client
|
||||
storageOpts := storage.Options{
|
||||
NewGitClient: func(url, user, token, path string) git.Client {
|
||||
NewGitClient: func(url, user, token, path, commitName, commitEmail string) git.Client {
|
||||
return mockGit
|
||||
},
|
||||
}
|
||||
|
||||
@@ -64,6 +64,8 @@ func (h *Handler) CreateWorkspace() http.HandlerFunc {
|
||||
workspace.GitURL,
|
||||
workspace.GitUser,
|
||||
workspace.GitToken,
|
||||
workspace.GitCommitName,
|
||||
workspace.GitCommitEmail,
|
||||
); err != nil {
|
||||
http.Error(w, "Failed to setup git repo: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -96,7 +98,9 @@ func gitSettingsChanged(new, old *models.Workspace) bool {
|
||||
if new.GitEnabled {
|
||||
return new.GitURL != old.GitURL ||
|
||||
new.GitUser != old.GitUser ||
|
||||
new.GitToken != old.GitToken
|
||||
new.GitToken != old.GitToken ||
|
||||
new.GitCommitName != old.GitCommitName ||
|
||||
new.GitCommitEmail != old.GitCommitEmail
|
||||
}
|
||||
|
||||
return false
|
||||
@@ -135,6 +139,8 @@ func (h *Handler) UpdateWorkspace() http.HandlerFunc {
|
||||
workspace.GitURL,
|
||||
workspace.GitUser,
|
||||
workspace.GitToken,
|
||||
workspace.GitCommitName,
|
||||
workspace.GitCommitEmail,
|
||||
); err != nil {
|
||||
http.Error(w, "Failed to setup git repo: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -54,12 +54,14 @@ func TestWorkspaceHandlers_Integration(t *testing.T) {
|
||||
|
||||
t.Run("create with git settings", func(t *testing.T) {
|
||||
workspace := &models.Workspace{
|
||||
Name: "Git Workspace",
|
||||
GitEnabled: true,
|
||||
GitURL: "https://github.com/test/repo.git",
|
||||
GitUser: "testuser",
|
||||
GitToken: "testtoken",
|
||||
GitAutoCommit: true,
|
||||
Name: "Git Workspace",
|
||||
GitEnabled: true,
|
||||
GitURL: "https://github.com/test/repo.git",
|
||||
GitUser: "testuser",
|
||||
GitToken: "testtoken",
|
||||
GitAutoCommit: true,
|
||||
GitCommitName: "Test User",
|
||||
GitCommitEmail: "test@example.com",
|
||||
}
|
||||
|
||||
rr := h.makeRequest(t, http.MethodPost, "/api/v1/workspaces", workspace, h.RegularToken, nil)
|
||||
@@ -73,6 +75,8 @@ func TestWorkspaceHandlers_Integration(t *testing.T) {
|
||||
assert.Equal(t, workspace.GitUser, created.GitUser)
|
||||
assert.Equal(t, workspace.GitToken, created.GitToken)
|
||||
assert.Equal(t, workspace.GitAutoCommit, created.GitAutoCommit)
|
||||
assert.Equal(t, workspace.GitCommitName, created.GitCommitName)
|
||||
assert.Equal(t, workspace.GitCommitEmail, created.GitCommitEmail)
|
||||
})
|
||||
|
||||
t.Run("invalid workspace", func(t *testing.T) {
|
||||
@@ -161,13 +165,15 @@ func TestWorkspaceHandlers_Integration(t *testing.T) {
|
||||
|
||||
t.Run("enable git", func(t *testing.T) {
|
||||
update := &models.Workspace{
|
||||
Name: workspace.Name,
|
||||
Theme: "dark",
|
||||
GitEnabled: true,
|
||||
GitURL: "https://github.com/test/repo.git",
|
||||
GitUser: "testuser",
|
||||
GitToken: "testtoken",
|
||||
GitAutoCommit: true,
|
||||
Name: workspace.Name,
|
||||
Theme: "dark",
|
||||
GitEnabled: true,
|
||||
GitURL: "https://github.com/test/repo.git",
|
||||
GitUser: "testuser",
|
||||
GitToken: "testtoken",
|
||||
GitAutoCommit: true,
|
||||
GitCommitName: "Test User",
|
||||
GitCommitEmail: "test@example.com",
|
||||
}
|
||||
|
||||
rr := h.makeRequest(t, http.MethodPut, baseURL, update, h.RegularToken, nil)
|
||||
@@ -180,6 +186,8 @@ func TestWorkspaceHandlers_Integration(t *testing.T) {
|
||||
assert.Equal(t, update.GitURL, updated.GitURL)
|
||||
assert.Equal(t, update.GitUser, updated.GitUser)
|
||||
assert.Equal(t, update.GitToken, updated.GitToken)
|
||||
assert.Equal(t, update.GitAutoCommit, updated.GitAutoCommit)
|
||||
assert.Equal(t, update.GitCommitName, updated.GitCommitName)
|
||||
|
||||
// Mock should have been called to setup git
|
||||
assert.True(t, h.MockGit.IsInitialized())
|
||||
|
||||
Reference in New Issue
Block a user