@@ -275,6 +275,84 @@ func TestCloneOrOpenLanguageRepo(t *testing.T) {
275275 }
276276}
277277
278+ func TestCleanAndCopyLibrary (t * testing.T ) {
279+ t .Parallel ()
280+ for _ , test := range []struct {
281+ name string
282+ libraryID string
283+ state * config.LibrarianState
284+ repo gitrepo.Repository
285+ outputDir string
286+ setup func (t * testing.T , outputDir string )
287+ wantErr bool
288+ errContains string
289+ }{
290+ {
291+ name : "library not found" ,
292+ libraryID : "non-existent-library" ,
293+ state : & config.LibrarianState {
294+ Libraries : []* config.LibraryState {
295+ {
296+ ID : "some-library" ,
297+ },
298+ },
299+ },
300+ repo : newTestGitRepo (t ),
301+ wantErr : true ,
302+ },
303+ {
304+ name : "clean fails" ,
305+ libraryID : "some-library" ,
306+ state : & config.LibrarianState {
307+ Libraries : []* config.LibraryState {
308+ {
309+ ID : "some-library" ,
310+ RemoveRegex : []string {"[" }, // Invalid regex
311+ },
312+ },
313+ },
314+ repo : newTestGitRepo (t ),
315+ wantErr : true ,
316+ },
317+ {
318+ name : "copy fails on symlink" ,
319+ libraryID : "some-library" ,
320+ state : & config.LibrarianState {
321+ Libraries : []* config.LibraryState {
322+ {
323+ ID : "some-library" ,
324+ },
325+ },
326+ },
327+ repo : newTestGitRepo (t ),
328+ setup : func (t * testing.T , outputDir string ) {
329+ // Create a symlink in the output directory to trigger an error.
330+ if err := os .Symlink ("target" , filepath .Join (outputDir , "symlink" )); err != nil {
331+ t .Fatalf ("os.Symlink() = %v" , err )
332+ }
333+ },
334+ wantErr : true ,
335+ },
336+ } {
337+ t .Run (test .name , func (t * testing.T ) {
338+ outputDir := t .TempDir ()
339+ if test .setup != nil {
340+ test .setup (t , outputDir )
341+ }
342+ err := cleanAndCopyLibrary (test .state , test .repo .GetDir (), test .libraryID , outputDir )
343+ if test .wantErr {
344+ if err == nil {
345+ t .Errorf ("%s should return error" , test .name )
346+ }
347+ return
348+ }
349+ if err != nil {
350+ t .Fatal (err )
351+ }
352+ })
353+ }
354+ }
355+
278356func TestCommitAndPush (t * testing.T ) {
279357 for _ , test := range []struct {
280358 name string
0 commit comments