@@ -1782,19 +1782,20 @@ func TestCopyLibraryFiles(t *testing.T) {
17821782 }
17831783 }
17841784 for _ , test := range []struct {
1785- name string
1786- repoDir string
1787- outputDir string
1788- libraryID string
1789- state * config.LibrarianState
1790- existingFiles []string
1791- filesToCreate []string
1792- setup func (t * testing.T , outputDir string )
1793- verify func (t * testing.T , repoDir string )
1794- wantFiles []string
1795- skipFiles []string
1796- wantErr bool
1797- wantErrMsg string
1785+ name string
1786+ repoDir string
1787+ outputDir string
1788+ libraryID string
1789+ state * config.LibrarianState
1790+ existingFiles []string
1791+ filesToCreate []string
1792+ setup func (t * testing.T , outputDir string )
1793+ verify func (t * testing.T , repoDir string )
1794+ wantFiles []string
1795+ skipFiles []string
1796+ failOnExistingFile bool
1797+ wantErr bool
1798+ wantErrMsg string
17981799 }{
17991800 {
18001801 repoDir : "/invalid-dst-path" ,
@@ -1960,6 +1961,33 @@ func TestCopyLibraryFiles(t *testing.T) {
19601961 "another/path/example.txt" ,
19611962 },
19621963 },
1964+ {
1965+ name : "file_existed_in_dst" ,
1966+ repoDir : filepath .Join (t .TempDir (), "dst" ),
1967+ outputDir : filepath .Join (t .TempDir (), "foo" ),
1968+ libraryID : "example-library" ,
1969+ state : & config.LibrarianState {
1970+ Libraries : []* config.LibraryState {
1971+ {
1972+ ID : "example-library" ,
1973+ SourceRoots : []string {
1974+ "a/path" ,
1975+ "another/path" ,
1976+ },
1977+ },
1978+ },
1979+ },
1980+ existingFiles : []string {
1981+ "a/path/example.txt" ,
1982+ },
1983+ filesToCreate : []string {
1984+ "a/path/example.txt" ,
1985+ "another/path/example.txt" ,
1986+ },
1987+ failOnExistingFile : true ,
1988+ wantErr : true ,
1989+ wantErrMsg : "file existed in destination" ,
1990+ },
19631991 } {
19641992 t .Run (test .name , func (t * testing.T ) {
19651993 if len (test .existingFiles ) > 0 {
@@ -1971,10 +1999,10 @@ func TestCopyLibraryFiles(t *testing.T) {
19711999 if test .setup != nil {
19722000 test .setup (t , test .outputDir )
19732001 }
1974- err := copyLibraryFiles (test .state , test .repoDir , test .libraryID , test .outputDir )
2002+ err := copyLibraryFiles (test .state , test .repoDir , test .libraryID , test .outputDir , test . failOnExistingFile )
19752003 if test .wantErr {
19762004 if err == nil {
1977- t .Fatal ("copyLibraryFiles() shoud fail" )
2005+ t .Fatal ("copyLibraryFiles() should fail" )
19782006 }
19792007 if ! strings .Contains (err .Error (), test .wantErrMsg ) {
19802008 t .Errorf ("want error message: %s, got: %s" , test .wantErrMsg , err .Error ())
0 commit comments