gitlink-cli/shortcuts/workflow/rules/init_scaffold_test.go

77 lines
2.2 KiB
Go

package rules
import (
"testing"
)
func TestInitScaffoldRuleActions(t *testing.T) {
upstream := map[string]interface{}{
"_owner": "testuser",
"_repo": "test-project",
"_desc": "A test project for CI/CD",
}
resp, err := InitScaffoldRule(upstream, "init-scaffold")
if err != nil {
t.Fatalf("InitScaffoldRule failed: %v", err)
}
if resp == nil {
t.Fatal("expected non-nil response")
}
if resp.Analysis == nil {
t.Fatal("expected analysis in response")
}
// Actions: 1 repo + 3 files + 7 labels + 1 milestone + 3 issues = 15
if len(resp.Actions) != 15 {
t.Errorf("expected 15 actions, got %d", len(resp.Actions))
}
// First action should be repo creation (CLI action).
if resp.Actions[0].Type != "cli" || resp.Actions[0].Command != "+create" {
t.Errorf("first action should be cli +create for repo creation, got type=%s command=%s",
resp.Actions[0].Type, resp.Actions[0].Command)
}
analysis := resp.Analysis.(map[string]interface{})
if files := analysis["files_created"].(int); files != 3 {
t.Errorf("files_created = %d, want 3", files)
}
if labels := analysis["labels_created"].(int); labels != 7 {
t.Errorf("labels_created = %d, want 7", labels)
}
if milestones := analysis["milestones_created"].(int); milestones != 1 {
t.Errorf("milestones_created = %d, want 1", milestones)
}
if issues := analysis["issues_created"].(int); issues != 3 {
t.Errorf("issues_created = %d, want 3", issues)
}
}
func TestInitScaffoldRuleWithDescription(t *testing.T) {
upstream := map[string]interface{}{
"_owner": "testuser",
"_desc": "Docker 容器管理平台",
}
resp, err := InitScaffoldRule(upstream, "init-scaffold")
if err != nil {
t.Fatalf("InitScaffoldRule failed: %v", err)
}
if resp == nil {
t.Fatal("expected non-nil response")
}
// Repo name should be auto-generated from description.
analysis := resp.Analysis.(map[string]interface{})
repo := analysis["repo"].(string)
if repo == "" || repo == "testuser/new-project" {
t.Errorf("expected auto-generated repo name, got %q", repo)
}
}
func TestInitScaffoldRuleMissingOwner(t *testing.T) {
_, err := InitScaffoldRule(map[string]interface{}{}, "init-scaffold")
if err == nil {
t.Fatal("expected error when _owner is missing")
}
}