(t *testing.T)
| 223 | } |
| 224 | |
| 225 | func TestCheckCacheNewDateHit(t *testing.T) { |
| 226 | testCases := []struct { |
| 227 | name string |
| 228 | expiryTimestamp string |
| 229 | }{ |
| 230 | { |
| 231 | name: "expiry date in the future", |
| 232 | expiryTimestamp: time.Now().Add(repoExpiration).Format(dateFormat), |
| 233 | }, |
| 234 | } |
| 235 | |
| 236 | for _, tc := range testCases { |
| 237 | t.Run(tc.name, func(t *testing.T) { |
| 238 | ctx := gcp.NewContext() |
| 239 | testFilePath, m2CachedRepo := setupTestLayer(t, ctx) |
| 240 | ctx.SetMetadata(m2CachedRepo, "expiry_timestamp", tc.expiryTimestamp) |
| 241 | |
| 242 | if err := CheckCacheExpiration(ctx, m2CachedRepo); err != nil { |
| 243 | t.Fatalf("CheckCacheExpiration() unexpected error = %q", err.Error()) |
| 244 | } |
| 245 | if got, want := ctx.GetMetadata(m2CachedRepo, "expiry_timestamp"), tc.expiryTimestamp; got != want { |
| 246 | t.Errorf("checkCacheExpiration() set new date when expected not to with ExpiryTimestamp: %q", got) |
| 247 | } |
| 248 | if _, err := os.Stat(testFilePath); err != nil { |
| 249 | t.Errorf("checkCacheExpiration() cleared layer") |
| 250 | } |
| 251 | // Clean up layer for next test case. |
| 252 | if err := os.RemoveAll(testFilePath); err != nil { |
| 253 | t.Fatalf("error cleaning up: %v", err) |
| 254 | } |
| 255 | }) |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | func setupTestLayer(t *testing.T, ctx *gcp.Context) (string, *libcnb.Layer) { |
| 260 | t.Helper() |
nothing calls this directly
no test coverage detected