tests: add functional tests for issues labels

This commit is contained in:
Romain Bertrand 2026-02-20 17:48:56 +01:00
parent 0b8f67e438
commit 2a20a4e0b8
2 changed files with 244 additions and 0 deletions

View file

@ -151,6 +151,74 @@ func (env *TestEnv) VerifyAPIConnection() {
}
}
// EnsureTestLabels creates test labels if they don't exist
func (env *TestEnv) EnsureTestLabels() {
labelNames := []string{"bug", "enhancement", "help-wanted"}
for _, name := range labelNames {
labels, _, err := env.Client.ListRepoLabels(env.Owner, env.RepoName, gitea.ListLabelsOptions{})
if err != nil {
env.T.Fatalf("failed to list labels: %v", err)
}
exists := false
for _, label := range labels {
if label.Name == name {
exists = true
break
}
}
if !exists {
color := "#00aabb"
if name == "bug" {
color = "#ff0000"
} else if name == "enhancement" {
color = "#00ff00"
}
_, _, err = env.Client.CreateLabel(env.Owner, env.RepoName, gitea.CreateLabelOption{
Name: name,
Color: color,
})
if err != nil {
env.T.Logf("warning: failed to create label '%s': %v", name, err)
} else {
env.T.Logf("Created test label: %s", name)
}
}
}
}
// GetIssueLabels gets the labels on an issue
func (env *TestEnv) GetIssueLabels(issueNumber int64) ([]*gitea.Label, error) {
labels, _, err := env.Client.GetIssueLabels(env.Owner, env.RepoName, issueNumber, gitea.ListLabelsOptions{})
return labels, err
}
// GetLabelIDs converts label names to label IDs
func (env *TestEnv) GetLabelIDs(labelNames []string) []int64 {
labels, _, err := env.Client.ListRepoLabels(env.Owner, env.RepoName, gitea.ListLabelsOptions{})
if err != nil {
env.T.Fatalf("failed to list labels: %v", err)
}
nameToID := make(map[string]int64)
for _, label := range labels {
nameToID[label.Name] = label.ID
}
var ids []int64
for _, name := range labelNames {
id, exists := nameToID[name]
if !exists {
env.T.Fatalf("label '%s' not found", name)
}
ids = append(ids, id)
}
return ids
}
// GetBinaryPath returns the path to the built fgj binary
func (env *TestEnv) GetBinaryPath() string {
binaryPath := os.Getenv("FGJ_BINARY_PATH")