tests: add functional tests for issues labels
This commit is contained in:
parent
0b8f67e438
commit
2a20a4e0b8
2 changed files with 244 additions and 0 deletions
|
|
@ -103,6 +103,182 @@ func TestCreateAndListIssues(t *testing.T) {
|
|||
t.Logf("Successfully created and listed issue #%d", issueNum)
|
||||
}
|
||||
|
||||
// TestIssueCreateWithLabels verifies we can create issues with labels via CLI
|
||||
func TestIssueCreateWithLabels(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
|
||||
// Ensure test labels exist
|
||||
env.EnsureTestLabels()
|
||||
|
||||
// Create an issue with labels via CLI
|
||||
result := env.RunCLI(
|
||||
"--hostname", env.Hostname,
|
||||
"issue", "create",
|
||||
"-t", "[FGJ E2E Test] Issue with Labels",
|
||||
"-b", "This issue was created with labels",
|
||||
"-l", "bug",
|
||||
"-l", "enhancement",
|
||||
)
|
||||
|
||||
if result.ExitCode != 0 {
|
||||
t.Fatalf("issue create with labels failed with exit code %d: %s", result.ExitCode, result.Stderr)
|
||||
}
|
||||
|
||||
// Extract issue number from output (format: "Issue created: #<number>")
|
||||
var issueNum int64
|
||||
_, err := fmt.Sscanf(result.Stdout, "Issue created: #%d", &issueNum)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse issue number from output: %v", err)
|
||||
}
|
||||
|
||||
defer env.CleanupIssue(issueNum)
|
||||
|
||||
// Verify labels were applied
|
||||
labels, err := env.GetIssueLabels(issueNum)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get issue labels: %v", err)
|
||||
}
|
||||
|
||||
if len(labels) != 2 {
|
||||
t.Fatalf("expected 2 labels, got %d", len(labels))
|
||||
}
|
||||
|
||||
labelNames := make(map[string]bool)
|
||||
for _, label := range labels {
|
||||
labelNames[label.Name] = true
|
||||
}
|
||||
|
||||
if !labelNames["bug"] || !labelNames["enhancement"] {
|
||||
t.Fatalf("expected labels 'bug' and 'enhancement', got %v", labelNames)
|
||||
}
|
||||
|
||||
t.Logf("Successfully created issue #%d with labels: bug, enhancement", issueNum)
|
||||
}
|
||||
|
||||
// TestIssueEditAddLabels verifies we can add labels to an issue via CLI
|
||||
func TestIssueEditAddLabels(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
|
||||
// Ensure test labels exist
|
||||
env.EnsureTestLabels()
|
||||
|
||||
// Create an issue without labels
|
||||
issueNum := env.CreateTestIssue(
|
||||
"[FGJ E2E Test] Add Labels Test",
|
||||
"This issue will have labels added",
|
||||
)
|
||||
defer env.CleanupIssue(issueNum)
|
||||
|
||||
// Verify no labels initially
|
||||
labels, err := env.GetIssueLabels(issueNum)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get initial labels: %v", err)
|
||||
}
|
||||
|
||||
if len(labels) != 0 {
|
||||
t.Fatalf("expected 0 labels initially, got %d", len(labels))
|
||||
}
|
||||
|
||||
// Add labels via CLI
|
||||
result := env.RunCLI(
|
||||
"--hostname", env.Hostname,
|
||||
"issue", "edit",
|
||||
fmt.Sprintf("%d", issueNum),
|
||||
"--add-label", "bug",
|
||||
"--add-label", "help-wanted",
|
||||
)
|
||||
|
||||
if result.ExitCode != 0 {
|
||||
t.Fatalf("issue edit add-label failed with exit code %d: %s", result.ExitCode, result.Stderr)
|
||||
}
|
||||
|
||||
// Verify labels were added
|
||||
labels, err = env.GetIssueLabels(issueNum)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get labels after edit: %v", err)
|
||||
}
|
||||
|
||||
if len(labels) != 2 {
|
||||
t.Fatalf("expected 2 labels after edit, got %d", len(labels))
|
||||
}
|
||||
|
||||
labelNames := make(map[string]bool)
|
||||
for _, label := range labels {
|
||||
labelNames[label.Name] = true
|
||||
}
|
||||
|
||||
if !labelNames["bug"] || !labelNames["help-wanted"] {
|
||||
t.Fatalf("expected labels 'bug' and 'help-wanted', got %v", labelNames)
|
||||
}
|
||||
|
||||
t.Logf("Successfully added labels to issue #%d", issueNum)
|
||||
}
|
||||
|
||||
// TestIssueEditRemoveLabels verifies we can remove labels from an issue via CLI
|
||||
func TestIssueEditRemoveLabels(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
|
||||
// Ensure test labels exist
|
||||
env.EnsureTestLabels()
|
||||
|
||||
// Create an issue with labels
|
||||
issue, _, err := env.Client.CreateIssue(env.Owner, env.RepoName, gitea.CreateIssueOption{
|
||||
Title: "[FGJ E2E Test] Remove Labels Test",
|
||||
Body: "This issue will have labels removed",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create issue: %v", err)
|
||||
}
|
||||
defer env.CleanupIssue(issue.Index)
|
||||
|
||||
// Add labels via API
|
||||
labelIDs := env.GetLabelIDs([]string{"bug", "enhancement"})
|
||||
_, _, err = env.Client.AddIssueLabels(env.Owner, env.RepoName, issue.Index, gitea.IssueLabelsOption{
|
||||
Labels: labelIDs,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to add initial labels: %v", err)
|
||||
}
|
||||
|
||||
// Verify initial labels
|
||||
labels, err := env.GetIssueLabels(issue.Index)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get initial labels: %v", err)
|
||||
}
|
||||
|
||||
if len(labels) != 2 {
|
||||
t.Fatalf("expected 2 labels initially, got %d", len(labels))
|
||||
}
|
||||
|
||||
// Remove one label via CLI
|
||||
result := env.RunCLI(
|
||||
"--hostname", env.Hostname,
|
||||
"issue", "edit",
|
||||
fmt.Sprintf("%d", issue.Index),
|
||||
"--remove-label", "bug",
|
||||
)
|
||||
|
||||
if result.ExitCode != 0 {
|
||||
t.Fatalf("issue edit remove-label failed with exit code %d: %s", result.ExitCode, result.Stderr)
|
||||
}
|
||||
|
||||
// Verify label was removed
|
||||
labels, err = env.GetIssueLabels(issue.Index)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get labels after edit: %v", err)
|
||||
}
|
||||
|
||||
if len(labels) != 1 {
|
||||
t.Fatalf("expected 1 label after removal, got %d", len(labels))
|
||||
}
|
||||
|
||||
if labels[0].Name != "enhancement" {
|
||||
t.Fatalf("expected remaining label 'enhancement', got '%s'", labels[0].Name)
|
||||
}
|
||||
|
||||
t.Logf("Successfully removed label from issue #%d", issue.Index)
|
||||
}
|
||||
|
||||
// TestGetIssue verifies we can get issue details
|
||||
func TestGetIssue(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue