@@ -1225,17 +1225,17 @@ func TestGitRepositoryReconciler_reconcileStorage(t *testing.T) {
12251225 Path : fmt .Sprintf ("/reconcile-storage/%s.txt" , v ),
12261226 Revision : v ,
12271227 }
1228- if err := testStorage .MkdirAll (* obj .Status .Artifact ); err != nil {
1228+ if err := storage .MkdirAll (* obj .Status .Artifact ); err != nil {
12291229 return err
12301230 }
1231- if err := testStorage .AtomicWriteFile (obj .Status .Artifact , strings .NewReader (v ), 0o640 ); err != nil {
1231+ if err := storage .AtomicWriteFile (obj .Status .Artifact , strings .NewReader (v ), 0o640 ); err != nil {
12321232 return err
12331233 }
12341234 if n != len (revisions )- 1 {
12351235 time .Sleep (time .Second * 1 )
12361236 }
12371237 }
1238- testStorage .SetArtifactURL (obj .Status .Artifact )
1238+ storage .SetArtifactURL (obj .Status .Artifact )
12391239 conditions .MarkTrue (obj , meta .ReadyCondition , "foo" , "bar" )
12401240 return nil
12411241 },
@@ -1272,7 +1272,7 @@ func TestGitRepositoryReconciler_reconcileStorage(t *testing.T) {
12721272 Path : "/reconcile-storage/invalid.txt" ,
12731273 Revision : "e" ,
12741274 }
1275- testStorage .SetArtifactURL (obj .Status .Artifact )
1275+ storage .SetArtifactURL (obj .Status .Artifact )
12761276 return nil
12771277 },
12781278 want : sreconcile .ResultSuccess ,
@@ -1284,6 +1284,68 @@ func TestGitRepositoryReconciler_reconcileStorage(t *testing.T) {
12841284 * conditions .UnknownCondition (meta .ReadyCondition , meta .ProgressingReason , "building artifact: disappeared from storage" ),
12851285 },
12861286 },
1287+ {
1288+ name : "notices empty artifact digest" ,
1289+ beforeFunc : func (obj * sourcev1.GitRepository , storage * Storage ) error {
1290+ f := "empty-digest.txt"
1291+
1292+ obj .Status .Artifact = & sourcev1.Artifact {
1293+ Path : fmt .Sprintf ("/reconcile-storage/%s.txt" , f ),
1294+ Revision : "fake" ,
1295+ }
1296+
1297+ if err := storage .MkdirAll (* obj .Status .Artifact ); err != nil {
1298+ return err
1299+ }
1300+ if err := storage .AtomicWriteFile (obj .Status .Artifact , strings .NewReader (f ), 0o600 ); err != nil {
1301+ return err
1302+ }
1303+
1304+ // Overwrite with a different digest
1305+ obj .Status .Artifact .Digest = ""
1306+
1307+ return nil
1308+ },
1309+ want : sreconcile .ResultSuccess ,
1310+ assertPaths : []string {
1311+ "!/reconcile-storage/empty-digest.txt" ,
1312+ },
1313+ assertConditions : []metav1.Condition {
1314+ * conditions .TrueCondition (meta .ReconcilingCondition , meta .ProgressingReason , "building artifact: disappeared from storage" ),
1315+ * conditions .UnknownCondition (meta .ReadyCondition , meta .ProgressingReason , "building artifact: disappeared from storage" ),
1316+ },
1317+ },
1318+ {
1319+ name : "notices artifact digest mismatch" ,
1320+ beforeFunc : func (obj * sourcev1.GitRepository , storage * Storage ) error {
1321+ f := "digest-mismatch.txt"
1322+
1323+ obj .Status .Artifact = & sourcev1.Artifact {
1324+ Path : fmt .Sprintf ("/reconcile-storage/%s.txt" , f ),
1325+ Revision : "fake" ,
1326+ }
1327+
1328+ if err := storage .MkdirAll (* obj .Status .Artifact ); err != nil {
1329+ return err
1330+ }
1331+ if err := storage .AtomicWriteFile (obj .Status .Artifact , strings .NewReader (f ), 0o600 ); err != nil {
1332+ return err
1333+ }
1334+
1335+ // Overwrite with a different digest
1336+ obj .Status .Artifact .Digest = "sha256:6c329d5322473f904e2f908a51c12efa0ca8aa4201dd84f2c9d203a6ab3e9023"
1337+
1338+ return nil
1339+ },
1340+ want : sreconcile .ResultSuccess ,
1341+ assertPaths : []string {
1342+ "!/reconcile-storage/digest-mismatch.txt" ,
1343+ },
1344+ assertConditions : []metav1.Condition {
1345+ * conditions .TrueCondition (meta .ReconcilingCondition , meta .ProgressingReason , "building artifact: disappeared from storage" ),
1346+ * conditions .UnknownCondition (meta .ReadyCondition , meta .ProgressingReason , "building artifact: disappeared from storage" ),
1347+ },
1348+ },
12871349 {
12881350 name : "updates hostname on diff from current" ,
12891351 beforeFunc : func (obj * sourcev1.GitRepository , storage * Storage ) error {
@@ -1293,10 +1355,10 @@ func TestGitRepositoryReconciler_reconcileStorage(t *testing.T) {
12931355 Digest : "sha256:3b9c358f36f0a31b6ad3e14f309c7cf198ac9246e8316f9ce543d5b19ac02b80" ,
12941356 URL : "http://outdated.com/reconcile-storage/hostname.txt" ,
12951357 }
1296- if err := testStorage .MkdirAll (* obj .Status .Artifact ); err != nil {
1358+ if err := storage .MkdirAll (* obj .Status .Artifact ); err != nil {
12971359 return err
12981360 }
1299- if err := testStorage .AtomicWriteFile (obj .Status .Artifact , strings .NewReader ("file" ), 0o640 ); err != nil {
1361+ if err := storage .AtomicWriteFile (obj .Status .Artifact , strings .NewReader ("file" ), 0o640 ); err != nil {
13001362 return err
13011363 }
13021364 conditions .MarkTrue (obj , meta .ReadyCondition , "foo" , "bar" )
0 commit comments