(t *testing.T)
| 59 | } |
| 60 | |
| 61 | func Test_CreateRepository_PreventDeletion(t *testing.T) { |
| 62 | tempRepositoryRoot := filepath.Join(os.TempDir(), "createRepository-tempRepositoryRoot") |
| 63 | conf.SetMockRepository( |
| 64 | t, |
| 65 | conf.RepositoryOpts{ |
| 66 | Root: tempRepositoryRoot, |
| 67 | }, |
| 68 | ) |
| 69 | err := os.RemoveAll(tempRepositoryRoot) |
| 70 | require.NoError(t, err) |
| 71 | defer func() { _ = os.RemoveAll(tempRepositoryRoot) }() |
| 72 | |
| 73 | owner := &User{Name: "testuser"} |
| 74 | opts := CreateRepoOptionsLegacy{Name: "safety-test"} |
| 75 | repoPath := RepoPath(owner.Name, opts.Name) |
| 76 | require.NoError(t, os.MkdirAll(repoPath, os.ModePerm)) |
| 77 | |
| 78 | canary := filepath.Join(repoPath, "canary.txt") |
| 79 | require.NoError(t, os.WriteFile(canary, []byte("should survive"), 0o644)) |
| 80 | |
| 81 | _, err = CreateRepository(owner, owner, opts) |
| 82 | require.Error(t, err) |
| 83 | assert.Contains(t, err.Error(), "repository directory already exists") |
| 84 | assert.True(t, osutil.Exist(canary)) |
| 85 | } |
nothing calls this directly
no test coverage detected