(t *testing.T)
| 176 | } |
| 177 | |
| 178 | func 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 | |
| 225 | func TestCheckCacheNewDateHit(t *testing.T) { |
| 226 | testCases := []struct { |
nothing calls this directly
no test coverage detected