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

Function TestAddCommandUpdatesGitAttributes

pkg/cli/add_gitattributes_test.go:15–163  ·  view source on GitHub ↗

TestAddCommandUpdatesGitAttributes tests that the add command updates .gitattributes by default

(t *testing.T)

Source from the content-addressed store, hash-verified

13
14// TestAddCommandUpdatesGitAttributes tests that the add command updates .gitattributes by default
15func TestAddCommandUpdatesGitAttributes(t *testing.T) {
16 // Create a temporary directory for testing
17 tmpDir, err := os.MkdirTemp("", "gh-aw-add-gitattributes-test")
18 if err != nil {
19 t.Fatalf("Failed to create temp dir: %v", err)
20 }
21 defer os.RemoveAll(tmpDir)
22
23 // Change to temp directory
24 originalDir, err := os.Getwd()
25 if err != nil {
26 t.Fatalf("Failed to get current directory: %v", err)
27 }
28 defer func() {
29 _ = os.Chdir(originalDir)
30 }()
31
32 if err := os.Chdir(tmpDir); err != nil {
33 t.Fatalf("Failed to change to temp directory: %v", err)
34 }
35
36 // Initialize a git repository
37 if err := os.WriteFile("test.txt", []byte("test"), 0644); err != nil {
38 t.Fatalf("Failed to create test file: %v", err)
39 }
40 if cmd := exec.Command("git", "init"); cmd.Run() != nil {
41 t.Skip("Skipping test - git not available")
42 }
43 if cmd := exec.Command("git", "config", "user.email", "test@example.com"); cmd.Run() != nil {
44 t.Skip("Skipping test - git config failed")
45 }
46 if cmd := exec.Command("git", "config", "user.name", "Test User"); cmd.Run() != nil {
47 t.Skip("Skipping test - git config failed")
48 }
49
50 // Create .github/workflows directory
51 workflowsDir := filepath.Join(tmpDir, ".github", "workflows")
52 if err := os.MkdirAll(workflowsDir, 0755); err != nil {
53 t.Fatalf("Failed to create .github/workflows directory: %v", err)
54 }
55
56 // Create a minimal workflow content for testing
57 workflowContent := `---
58on: push
59permissions:
60 contents: read
61engine: copilot
62---
63
64# Test Workflow
65
66This is a test workflow.`
67
68 // Create a ResolvedWorkflow for testing
69 resolved := &ResolvedWorkflow{
70 Spec: &WorkflowSpec{
71 RepoSpec: RepoSpec{
72 RepoSlug: "test/repo",

Callers

nothing calls this directly

Calls 4

addWorkflowsFunction · 0.85
BackgroundMethod · 0.80
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected