Files
vikunja/veans/e2e/shared_test.go
Tink bot c4a0575305 feat(veans): offer "create a new project" from init's picker
The project picker used to require at least one pre-existing project
and would otherwise hard-error: "no projects visible to this user —
create one in the Vikunja UI first". Now it always offers an extra
numbered entry "Create a new project" and, when the user picks it,
prompts for a title (required) + identifier (optional). Empty-list
case routes straight to creation.

Backed by a new client.CreateProject(ctx, *Project) method (`PUT
/projects`); the e2e harness now uses that instead of the raw c.Do
call it did before.

Also fixed a latent bufio bug in StdPrompter.ReadLine that this work
surfaced: every call created a fresh bufio.Reader, which read-ahead a
buffer and threw it away on return. Second+ prompts read empty. Reuse
one buffered reader on the StdPrompter instance.
2026-05-27 08:21:57 +00:00

75 lines
2.3 KiB
Go

// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-present Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package e2e
import (
"os/exec"
"strconv"
"strings"
"testing"
"code.vikunja.io/veans/internal/config"
)
// provisionWorkspace runs `veans init` against a fresh project and returns
// the workspace + harness primed for command-level e2e tests. Each test that
// needs a working .veans.yml calls this at the top.
func provisionWorkspace(t *testing.T) (*Workspace, *Harness) {
t.Helper()
h := New(t)
suffix := uniqueSuffix()
project := h.CreateProject(t, "veans-e2e-"+suffix, identifier(suffix))
view := h.FindKanbanView(t, project.ID)
ws := h.NewWorkspace(t)
ws.BotUsername = "bot-veans-e2e-" + suffix
_, stderr, code := h.Run(t, ws,
"init",
"--server", h.APIURL,
"--token", h.AdminToken,
"--project", strconv.FormatInt(project.ID, 10),
"--view", strconv.FormatInt(view.ID, 10),
"--bot-username", ws.BotUsername,
"--yes-buckets",
)
if code != 0 {
t.Fatalf("provision init failed: %s", stderr)
}
return ws, h
}
// loadConfig reads .veans.yml out of a workspace.
func loadConfig(t *testing.T, ws *Workspace) *config.Config {
t.Helper()
c, err := config.Load(ws.ConfigPath)
if err != nil {
t.Fatal(err)
}
return c
}
// gitInWorkspace runs git inside the workspace and fails the test on error.
func gitInWorkspace(t *testing.T, ws *Workspace, args ...string) {
t.Helper()
cmd := exec.CommandContext(t.Context(), "git", args...)
cmd.Dir = ws.Dir
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("git %s: %v\n%s", strings.Join(args, " "), err, out)
}
}