MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/buildpacks / TestCheckCacheNewDateHit

Function TestCheckCacheNewDateHit

pkg/java/java_test.go:225–257  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

223}
224
225func 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
259func setupTestLayer(t *testing.T, ctx *gcp.Context) (string, *libcnb.Layer) {
260 t.Helper()

Callers

nothing calls this directly

Calls 7

SetMetadataMethod · 0.95
GetMetadataMethod · 0.95
setupTestLayerFunction · 0.85
CheckCacheExpirationFunction · 0.85
RemoveAllMethod · 0.80
AddMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected