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

Function TestCheckCacheNewDateMiss

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

Source from the content-addressed store, hash-verified

176}
177
178func TestCheckCacheNewDateMiss(t *testing.T) {
179 testCases := []struct {
180 name string
181 expiryTimestamp string
182 }{
183 {
184 name: "empty string",
185 expiryTimestamp: "",
186 },
187 {
188 name: "invalid format",
189 expiryTimestamp: "invalid format",
190 },
191 {
192 name: "old expiry date",
193 expiryTimestamp: time.Now().Truncate(repoExpiration).Format(dateFormat),
194 },
195 }
196
197 for _, tc := range testCases {
198 t.Run(tc.name, func(t *testing.T) {
199 ctx := gcp.NewContext()
200
201 testFilePath, m2CachedRepo := setupTestLayer(t, ctx)
202 ctx.SetMetadata(m2CachedRepo, "expiry_timestamp", tc.expiryTimestamp)
203
204 if err := CheckCacheExpiration(ctx, m2CachedRepo); err != nil {
205 t.Fatalf("CheckCacheExpiration() unexpected error = %q", err.Error())
206 }
207 metaExpiry := ctx.GetMetadata(m2CachedRepo, "expiry_timestamp")
208 if metaExpiry == tc.expiryTimestamp {
209 t.Errorf("checkCacheExpiration() did not set new date when expected to with ExpiryTimestamp: %q", metaExpiry)
210 }
211 testFilePathExists, err := ctx.FileExists(testFilePath)
212 if err != nil {
213 t.Fatalf("Error checking if file exists: %v", err)
214 }
215 if testFilePathExists {
216 if err := os.RemoveAll(testFilePath); err != nil {
217 t.Errorf("error cleaning up: %v", err)
218 }
219 t.Errorf("checkCacheExpiration() did not clear layer")
220 }
221 })
222 }
223}
224
225func TestCheckCacheNewDateHit(t *testing.T) {
226 testCases := []struct {

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected