(t *testing.T)
| 217 | } |
| 218 | |
| 219 | func TestDevRestore_TamperedMetaFails(t *testing.T) { |
| 220 | cache := newTestDevArtifactCache(t) |
| 221 | pkgDir := makePackageDir(t, "glog@0.6.0") |
| 222 | |
| 223 | const meta = "original-meta" |
| 224 | if err := cache.Store(pkgDir, meta); err != nil { |
| 225 | t.Fatal(err) |
| 226 | } |
| 227 | hash := computeHash(meta) |
| 228 | |
| 229 | // Tamper with the meta file content — hash no longer matches content. |
| 230 | metaPath := filepath.Join(cache.cacheDir, "glog@0.6.0", "metas", hash+".meta") |
| 231 | if err := os.WriteFile(metaPath, []byte("tampered"), os.ModePerm); err != nil { |
| 232 | t.Fatal(err) |
| 233 | } |
| 234 | |
| 235 | destDir := filepath.Join(t.TempDir(), "dest") |
| 236 | fromPath, err := cache.Restore("glog@0.6.0", hash, destDir) |
| 237 | if err != nil { |
| 238 | t.Fatalf("Restore should not error on tampered meta, just miss: %v", err) |
| 239 | } |
| 240 | if fromPath != "" { |
| 241 | t.Error("expected cache miss when meta is tampered, got cache hit") |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | func TestDevRestore_DifferentHashMisses(t *testing.T) { |
| 246 | cache := newTestDevArtifactCache(t) |
nothing calls this directly
no test coverage detected