@@ -44,6 +44,54 @@ func TestPullRepository(t *testing.T) {
4444 assert .DirExists (t , artifactDir )
4545 })
4646
47+ t .Run ("success_with_single_file_artifact" , func (t * testing.T ) {
48+ tmpDir , err := os .MkdirTemp ("" , "go-common-test-" )
49+ require .NoError (t , err )
50+ defer os .RemoveAll (tmpDir )
51+
52+ art := & artifact.Artifact {
53+ Name : "my-repo" ,
54+ URL : "https://github.com/example/my-repo.git" ,
55+ BaseDir : tmpDir ,
56+ RelativePath : "single-file.yaml" ,
57+ }
58+
59+ mockRepo := git .NewMockRepository (t )
60+ mockRepo .On ("PlainCloneContext" , mock .Anything , mock .Anything , mock .Anything ).
61+ Run (func (args mock.Arguments ) {
62+ cloneDestPath := args .Get (1 ).(string )
63+
64+ err = os .WriteFile (filepath .Join (cloneDestPath , "single-file.yaml" ), []byte ("file content" ), 0644 )
65+ require .NoError (t , err )
66+ err = os .WriteFile (filepath .Join (cloneDestPath , "other-file.yaml" ), []byte ("file content" ), 0644 )
67+ require .NoError (t , err )
68+ err = os .MkdirAll (filepath .Join (cloneDestPath , "example" ), 0755 )
69+ require .NoError (t , err )
70+ err = os .MkdirAll (filepath .Join (cloneDestPath , ".git" ), 0755 )
71+ require .NoError (t , err )
72+ }).
73+ Return (& gogit.Repository {}, nil )
74+
75+ opts := & RepositoryOptions {
76+ Repository : mockRepo ,
77+ }
78+
79+ result , err := PullRepository (context .Background (), art , opts )
80+
81+ require .NoError (t , err )
82+ require .NotNil (t , result )
83+
84+ finalDir := art .DestDir ()
85+ finalFile := filepath .Join (finalDir , "single-file.yaml" )
86+ noExistDir := filepath .Join (finalDir , "example" )
87+ noExistFile := filepath .Join (finalDir , "other-file.yaml" )
88+
89+ assert .DirExists (t , finalDir , "The final destination directory should be created" )
90+ assert .FileExists (t , finalFile , "The artifact file should exist in the destination directory" )
91+ assert .NoDirExists (t , noExistDir , "The final destination should not contain example directory" )
92+ assert .NoFileExists (t , noExistFile , "The final destination should not contain other-file.yaml" )
93+ })
94+
4795 t .Run ("error_no_repository" , func (t * testing.T ) {
4896 art := & artifact.Artifact {
4997 Name : "my-repo" ,
0 commit comments