MCPcopy Create free account
hub / github.com/github/gh-aw / TestAddWorkflowsFromCurrentRepository

Function TestAddWorkflowsFromCurrentRepository

pkg/cli/add_current_repo_test.go:16–91  ·  view source on GitHub ↗

TestAddWorkflowsFromCurrentRepository tests that adding workflows from the current repository is prevented

(t *testing.T)

Source from the content-addressed store, hash-verified

14
15// TestAddWorkflowsFromCurrentRepository tests that adding workflows from the current repository is prevented
16func TestAddWorkflowsFromCurrentRepository(t *testing.T) {
17 // Create a temporary git repository to simulate being in a repository
18 tempDir := testutil.TempDir(t, "test-*")
19
20 // Initialize a proper git repository
21 initCmd := exec.Command("git", "init")
22 initCmd.Dir = tempDir
23 if err := initCmd.Run(); err != nil {
24 t.Fatalf("Failed to initialize git repository: %v", err)
25 }
26
27 // Add a remote origin
28 remoteCmd := exec.Command("git", "remote", "add", "origin", "https://github.com/test-owner/test-repo.git")
29 remoteCmd.Dir = tempDir
30 if err := remoteCmd.Run(); err != nil {
31 t.Fatalf("Failed to add remote origin: %v", err)
32 }
33
34 // Change to the temp directory
35 oldDir, err := os.Getwd()
36 if err != nil {
37 t.Fatalf("Failed to get current directory: %v", err)
38 }
39 defer os.Chdir(oldDir)
40
41 if err := os.Chdir(tempDir); err != nil {
42 t.Fatalf("Failed to change to temp directory: %v", err)
43 }
44
45 // Clear the repository slug cache to ensure fresh lookup
46 ClearCurrentRepoSlugCache()
47
48 tests := []struct {
49 name string
50 workflowSpecs []string
51 expectError bool
52 errorContains string
53 }{
54 {
55 name: "prevent adding workflow from current repository",
56 workflowSpecs: []string{"test-owner/test-repo/my-workflow"},
57 expectError: true,
58 errorContains: "cannot add workflows from the current repository",
59 },
60 {
61 name: "allow adding workflow from different repository",
62 workflowSpecs: []string{"different-owner/different-repo/workflow"},
63 expectError: false, // This will still fail because package doesn't exist, but not due to current repo check
64 },
65 }
66
67 for _, tt := range tests {
68 t.Run(tt.name, func(t *testing.T) {
69 // Clear cache before each test
70 ClearCurrentRepoSlugCache()
71
72 opts := AddOptions{}
73 _, err := AddWorkflows(context.Background(), tt.workflowSpecs, opts)

Callers

nothing calls this directly

Calls 7

TempDirFunction · 0.92
AddWorkflowsFunction · 0.85
BackgroundMethod · 0.80
RunMethod · 0.45
ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected