@@ -9,46 +9,48 @@ import (
99 "github.com/hackctl/hackctl/cli/internal/config"
1010)
1111
12- func TestEnsureGitignoreEntryCreatesFile (t * testing.T ) {
13- dir := t .TempDir ()
12+ func TestCopyDirectorySkipsSecretsAndGeneratedFiles (t * testing.T ) {
13+ sourceDir := t .TempDir ()
14+ destinationDir := t .TempDir ()
1415
15- if err := ensureGitignoreEntry ( dir , ".hackctl/" ); err != nil {
16- t .Fatalf ("unexpected error : %v" , err )
16+ if err := os . WriteFile ( filepath . Join ( sourceDir , ".env" ), [] byte ( "SECRET=1 \n " ), 0o644 ); err != nil {
17+ t .Fatalf ("could not write .env : %v" , err )
1718 }
18-
19- body , err := os .ReadFile (filepath .Join (dir , ".gitignore" ))
20- if err != nil {
21- t .Fatalf ("could not read .gitignore: %v" , err )
19+ if err := os .WriteFile (filepath .Join (sourceDir , ".env.example" ), []byte ("SECRET=\n " ), 0o644 ); err != nil {
20+ t .Fatalf ("could not write .env.example: %v" , err )
2221 }
23-
24- if string (body ) != ".hackctl/\n " {
25- t .Fatalf ("unexpected .gitignore content: %q" , string (body ))
22+ if err := os .WriteFile (filepath .Join (sourceDir , ".DS_Store" ), []byte ("junk" ), 0o644 ); err != nil {
23+ t .Fatalf ("could not write .DS_Store: %v" , err )
24+ }
25+ if err := os .MkdirAll (filepath .Join (sourceDir , "frontend" , "node_modules" ), 0o755 ); err != nil {
26+ t .Fatalf ("could not create node_modules: %v" , err )
27+ }
28+ if err := os .WriteFile (filepath .Join (sourceDir , "frontend" , "node_modules" , "pkg.txt" ), []byte ("x" ), 0o644 ); err != nil {
29+ t .Fatalf ("could not write node_modules file: %v" , err )
30+ }
31+ if err := os .WriteFile (filepath .Join (sourceDir , "frontend" , "app.js" ), []byte ("console.log('ok')\n " ), 0o644 ); err != nil {
32+ t .Fatalf ("could not write app file: %v" , err )
2633 }
27- }
28-
29- func TestEnsureGitignoreEntryAppendsWithoutDuplicates (t * testing.T ) {
30- dir := t .TempDir ()
31- gitignorePath := filepath .Join (dir , ".gitignore" )
3234
33- if err := os . WriteFile ( gitignorePath , [] byte ( "backend/.env \n " ), 0o644 ); err != nil {
34- t .Fatalf ("could not write seed .gitignore : %v" , err )
35+ if err := copyDirectory ( sourceDir , destinationDir ); err != nil {
36+ t .Fatalf ("copyDirectory failed : %v" , err )
3537 }
3638
37- if err := ensureGitignoreEntry ( dir , ".hackctl/" ) ; err ! = nil {
38- t .Fatalf ("unexpected error on first write: %v" , err )
39+ if _ , err := os . Stat ( filepath . Join ( destinationDir , ".env" )) ; err = = nil {
40+ t .Fatalf ("expected .env to be excluded" )
3941 }
40- if err := ensureGitignoreEntry ( dir , ".hackctl/" ) ; err ! = nil {
41- t .Fatalf ("unexpected error on second write: %v" , err )
42+ if _ , err := os . Stat ( filepath . Join ( destinationDir , ".DS_Store" )) ; err = = nil {
43+ t .Fatalf ("expected .DS_Store to be excluded" )
4244 }
43-
44- body , err := os .ReadFile (gitignorePath )
45- if err != nil {
46- t .Fatalf ("could not read .gitignore: %v" , err )
45+ if _ , err := os .Stat (filepath .Join (destinationDir , "frontend" , "node_modules" )); err == nil {
46+ t .Fatalf ("expected node_modules to be excluded" )
4747 }
4848
49- expected := "backend/.env\n .hackctl/\n "
50- if string (body ) != expected {
51- t .Fatalf ("unexpected .gitignore content: %q" , string (body ))
49+ if _ , err := os .Stat (filepath .Join (destinationDir , ".env.example" )); err != nil {
50+ t .Fatalf ("expected .env.example to be copied: %v" , err )
51+ }
52+ if _ , err := os .Stat (filepath .Join (destinationDir , "frontend" , "app.js" )); err != nil {
53+ t .Fatalf ("expected app file to be copied: %v" , err )
5254 }
5355}
5456
0 commit comments