(t *testing.T)
| 120 | } |
| 121 | |
| 122 | func TestBuildConfigClone_GitRepoCache(t *testing.T) { |
| 123 | // Goal: |
| 124 | // 1. An online git clone should be archived into repo pkgcache. |
| 125 | // 2. A later clone of the same commit should restore from pkgcache before |
| 126 | // touching the remote repository. |
| 127 | // |
| 128 | // Workspace globals are redirected into a temp dir so the test does not |
| 129 | // leak state into the developer's real workspace. |
| 130 | oldWorkspace := dirs.WorkspaceDir |
| 131 | tmpWorkspace := t.TempDir() |
| 132 | dirs.Init(tmpWorkspace) |
| 133 | t.Cleanup(func() { dirs.Init(oldWorkspace) }) |
| 134 | |
| 135 | pkgCacheDir := filepath.Join(tmpWorkspace, "pkgcache") |
| 136 | if err := os.MkdirAll(pkgCacheDir, os.ModePerm); err != nil { |
| 137 | t.Fatal(err) |
| 138 | } |
| 139 | |
| 140 | originURL, expectedCommit := setupGitOriginRepo(t, tmpWorkspace) |
| 141 | |
| 142 | // Create fake ports/x/x264, so that repo can be cached. |
| 143 | portPath := filepath.Join(dirs.PortsDir, "x", "x264", "stable") |
| 144 | if err := os.MkdirAll(filepath.Dir(portPath), os.ModePerm); err != nil { |
| 145 | t.Fatal(err) |
| 146 | } |
| 147 | repoDir := filepath.Join(tmpWorkspace, "buildtrees", "x264@stable", "src") |
| 148 | |
| 149 | t.Run("store repo cache after clone", func(t *testing.T) { |
| 150 | // This subtest only checks the write path: |
| 151 | // Clone() should create the source tree and also create the repo cache |
| 152 | // archive named by the resolved git commit. |
| 153 | ctx := fakeContext{ |
| 154 | platform: "x86_64-linux", |
| 155 | project: "proj", |
| 156 | build: "release", |
| 157 | pkgCacheConfig: fakePkgCacheConfig{ |
| 158 | dir: pkgCacheDir, |
| 159 | writable: true, |
| 160 | }, |
| 161 | } |
| 162 | |
| 163 | buildConfig := newBuildConfig(ctx, repoDir) |
| 164 | buildConfig.PortConfig.Checksum = expectedCommit |
| 165 | if err := buildConfig.Clone(originURL, "", "", 0); err != nil { |
| 166 | t.Fatal(err) |
| 167 | } |
| 168 | |
| 169 | // The cache key for git repos is the checked-out commit hash. |
| 170 | commit, err := git.GetCommitHash(repoDir) |
| 171 | if err != nil { |
| 172 | t.Fatal(err) |
| 173 | } |
| 174 | |
| 175 | archivePath := filepath.Join(pkgCacheDir, "repos", "x264@stable", commit+".tar.gz") |
| 176 | if !fileio.PathExists(archivePath) { |
| 177 | t.Fatalf("expected git repo cache archive: %s", archivePath) |
| 178 | } |
| 179 | }) |
nothing calls this directly
no test coverage detected