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

Function TestInitRepositoryBasic

pkg/cli/init_command_test.go:183–268  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

181}
182
183func TestInitRepositoryBasic(t *testing.T) {
184 tmpDir := testutil.TempDir(t, "test-*")
185
186 originalDir, err := os.Getwd()
187 if err != nil {
188 t.Fatalf("Failed to get current directory: %v", err)
189 }
190 defer func() {
191 _ = os.Chdir(originalDir)
192 }()
193
194 if err := os.Chdir(tmpDir); err != nil {
195 t.Fatalf("Failed to change to temp directory: %v", err)
196 }
197
198 // Initialize git repo (required for some init operations)
199 if err := exec.Command("git", "init").Run(); err != nil {
200 t.Skip("Git not available")
201 }
202
203 // Configure git
204 if err := exec.Command("git", "config", "user.name", "Test User").Run(); err != nil {
205 t.Fatalf("Failed to set git user.name: %v", err)
206 }
207 if err := exec.Command("git", "config", "user.email", "test@example.com").Run(); err != nil {
208 t.Fatalf("Failed to set git user.email: %v", err)
209 }
210
211 // Test basic init with MCP enabled by default (mcp=true, noMcp=false behavior)
212 err = InitRepository(InitOptions{Verbose: false, Skill: true, Agent: true, MCP: true, CodespaceRepos: []string{}, CodespaceEnabled: false, Completions: false, CreatePR: false, RootCmd: nil})
213 if err != nil {
214 t.Fatalf("InitRepository(, false, false, false, nil) failed: %v", err)
215 }
216
217 // Verify .gitattributes was created/updated
218 gitAttributesPath := ".gitattributes"
219 if _, err := os.Stat(gitAttributesPath); os.IsNotExist(err) {
220 t.Error("Expected .gitattributes to be created")
221 }
222
223 // Read and verify .gitattributes content
224 content, err := os.ReadFile(gitAttributesPath)
225 if err != nil {
226 t.Fatalf("Failed to read .gitattributes: %v", err)
227 }
228
229 expectedEntry := ".github/workflows/*.lock.yml linguist-generated=true merge=ours"
230 if !strings.Contains(string(content), expectedEntry) {
231 t.Errorf("Expected .gitattributes to contain %q", expectedEntry)
232 }
233
234 // Verify MCP files were created by default
235 mcpConfigPath := mcpConfigFilePath
236 if _, err := os.Stat(mcpConfigPath); os.IsNotExist(err) {
237 t.Error("Expected .github/mcp.json to be created by default")
238 }
239
240 setupStepsPath := filepath.Join(".github", "workflows", "copilot-setup-steps.yml")

Callers

nothing calls this directly

Calls 5

TempDirFunction · 0.92
InitRepositoryFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected