(t *testing.T)
| 242 | } |
| 243 | |
| 244 | func TestBuildConfigClone_ArchiveRepoCache(t *testing.T) { |
| 245 | // Goal: |
| 246 | // 1. An archive source should be unpacked once and then stored into repo |
| 247 | // pkgcache using the archive checksum as cache key. |
| 248 | // 2. A later clone should restore that unpacked source tree from repo |
| 249 | // pkgcache even if the original archive file has been removed. |
| 250 | // |
| 251 | // If archive repo-cache support is intentionally disabled in the product, |
| 252 | // this test should be removed or skipped rather than kept half-working. |
| 253 | oldWorkspace := dirs.WorkspaceDir |
| 254 | tmpWorkspace := t.TempDir() |
| 255 | dirs.Init(tmpWorkspace) |
| 256 | t.Cleanup(func() { dirs.Init(oldWorkspace) }) |
| 257 | |
| 258 | pkgCacheDir := filepath.Join(tmpWorkspace, "pkgcache") |
| 259 | downloadsDir := filepath.Join(tmpWorkspace, "downloads") |
| 260 | if err := os.MkdirAll(pkgCacheDir, os.ModePerm); err != nil { |
| 261 | t.Fatal(err) |
| 262 | } |
| 263 | if err := os.MkdirAll(downloadsDir, os.ModePerm); err != nil { |
| 264 | t.Fatal(err) |
| 265 | } |
| 266 | |
| 267 | archivePath, checksum := setupArchiveFile(t, tmpWorkspace) |
| 268 | |
| 269 | // Copy the archive into the downloads directory so Store can compute the |
| 270 | // SHA256 of the original archive file. For remote URLs Repair would have |
| 271 | // downloaded it there; for file:/// URLs Repair extracts directly without |
| 272 | // copying to downloads, so we do it explicitly for the test. |
| 273 | archiveBasename := filepath.Base(archivePath) |
| 274 | if err := fileio.CopyFile(archivePath, filepath.Join(downloadsDir, archiveBasename)); err != nil { |
| 275 | t.Fatal(err) |
| 276 | } |
| 277 | |
| 278 | repoURL := fmt.Sprintf("file:///%s", archivePath) |
| 279 | repoDir := filepath.Join(tmpWorkspace, "buildtrees", "x264@stable", "src") |
| 280 | |
| 281 | // First pass: unpack the archive and populate repo pkgcache. |
| 282 | onlineCtx := fakeContext{ |
| 283 | platform: "x86_64-linux", |
| 284 | project: "proj", |
| 285 | build: "release", |
| 286 | downloads: downloadsDir, |
| 287 | pkgCacheConfig: fakePkgCacheConfig{ |
| 288 | dir: pkgCacheDir, |
| 289 | writable: true, |
| 290 | }, |
| 291 | } |
| 292 | |
| 293 | // Create fake ports/x264/archive, so that repo can be cached. |
| 294 | portPath := filepath.Join(dirs.PortsDir, "x", "x264", "stable") |
| 295 | if err := os.MkdirAll(filepath.Dir(portPath), os.ModePerm); err != nil { |
| 296 | t.Fatal(err) |
| 297 | } |
| 298 | |
| 299 | onlineBuildConfig := newBuildConfig(onlineCtx, repoDir) |
| 300 | onlineBuildConfig.PortConfig.Checksum = checksum |
| 301 | if err := onlineBuildConfig.Clone(repoURL, checksum, "", 0); err != nil { |
nothing calls this directly
no test coverage detected