@@ -54,7 +54,7 @@ func TestExternalArtifact_LifeCycle(t *testing.T) {
5454 Namespace : ns .Name ,
5555 Name : "test-ea" ,
5656 }
57- ea , err := applyExternalArtifact (eaKey , revision )
57+ ea , err := applyExternalArtifact (eaKey , revision , "" )
5858 g .Expect (err ).ToNot (HaveOccurred (), "failed to create ExternalArtifact" )
5959
6060 // Create a HelmRelease that references the ExternalArtifact
@@ -80,24 +80,26 @@ func TestExternalArtifact_LifeCycle(t *testing.T) {
8080 g .Expect (err ).ToNot (HaveOccurred ())
8181
8282 t .Run ("installs from external artifact" , func (t * testing.T ) {
83- g .Eventually (func () bool {
83+ gt := NewWithT (t )
84+ gt .Eventually (func () bool {
8485 err = testEnv .Get (context .Background (), client .ObjectKeyFromObject (hr ), hr )
8586 if err != nil {
8687 return false
8788 }
8889 return apimeta .IsStatusConditionTrue (hr .Status .Conditions , meta .ReadyCondition )
8990 }, 5 * time .Second , time .Second ).Should (BeTrue (), "HelmRelease did not become ready" )
9091
91- g .Expect (hr .Status .LastAttemptedRevision ).To (Equal (revision ))
92- g .Expect (hr .Status .LastAttemptedReleaseAction ).To (Equal (v2 .ReleaseActionInstall ))
92+ gt .Expect (hr .Status .LastAttemptedRevision ).To (Equal (revision ))
93+ gt .Expect (hr .Status .LastAttemptedReleaseAction ).To (Equal (v2 .ReleaseActionInstall ))
9394 })
9495
9596 t .Run ("upgrades at external artifact revision change" , func (t * testing.T ) {
97+ gt := NewWithT (t )
9698 newRevision := "2.0.0"
97- ea , err = applyExternalArtifact (eaKey , newRevision )
98- g .Expect (err ).ToNot (HaveOccurred ())
99+ ea , err = applyExternalArtifact (eaKey , newRevision , "" )
100+ gt .Expect (err ).ToNot (HaveOccurred ())
99101
100- g .Eventually (func () bool {
102+ gt .Eventually (func () bool {
101103 err = testEnv .Get (context .Background (), client .ObjectKeyFromObject (hr ), hr )
102104 if err != nil {
103105 return false
@@ -106,42 +108,81 @@ func TestExternalArtifact_LifeCycle(t *testing.T) {
106108 hr .Status .LastAttemptedRevision == newRevision
107109 }, 5 * time .Second , time .Second ).Should (BeTrue (), "HelmRelease did not upgrade" )
108110
109- g .Expect (hr .Status .LastAttemptedReleaseAction ).To (Equal (v2 .ReleaseActionUpgrade ))
111+ gt .Expect (hr .Status .LastAttemptedReleaseAction ).To (Equal (v2 .ReleaseActionUpgrade ))
112+ })
113+
114+ t .Run ("upgrades at external artifact revision switch to digest" , func (t * testing.T ) {
115+ gt := NewWithT (t )
116+ fixedRevision := "2.0.0"
117+ newDigest := digest .FromString ("1" ).String ()
118+ ea , err = applyExternalArtifact (eaKey , fixedRevision , newDigest )
119+ gt .Expect (err ).ToNot (HaveOccurred ())
120+
121+ gt .Eventually (func () bool {
122+ err = testEnv .Get (context .Background (), client .ObjectKeyFromObject (hr ), hr )
123+ if err != nil {
124+ return false
125+ }
126+ return apimeta .IsStatusConditionTrue (hr .Status .Conditions , meta .ReadyCondition ) &&
127+ hr .Status .LastAttemptedRevisionDigest == newDigest
128+ }, 5 * time .Second , time .Second ).Should (BeTrue (), "HelmRelease did not upgrade" )
129+
130+ gt .Expect (hr .Status .LastAttemptedReleaseAction ).To (Equal (v2 .ReleaseActionUpgrade ))
131+ })
132+
133+ t .Run ("upgrades at external artifact digest change" , func (t * testing.T ) {
134+ gt := NewWithT (t )
135+ fixedRevision := "2.0.0"
136+ newDigest := digest .FromString ("2" ).String ()
137+ ea , err = applyExternalArtifact (eaKey , fixedRevision , newDigest )
138+ gt .Expect (err ).ToNot (HaveOccurred ())
139+
140+ gt .Eventually (func () bool {
141+ err = testEnv .Get (context .Background (), client .ObjectKeyFromObject (hr ), hr )
142+ if err != nil {
143+ return false
144+ }
145+ return apimeta .IsStatusConditionTrue (hr .Status .Conditions , meta .ReadyCondition ) &&
146+ hr .Status .LastAttemptedRevisionDigest == newDigest
147+ }, 5 * time .Second , time .Second ).Should (BeTrue (), "HelmRelease did not upgrade" )
148+
149+ gt .Expect (hr .Status .LastAttemptedReleaseAction ).To (Equal (v2 .ReleaseActionUpgrade ))
110150 })
111151
112152 t .Run ("fails when external artifact feature gate is disable" , func (t * testing.T ) {
113- newRevision := "3.0.0"
153+ gt := NewWithT ( t )
114154 reconciler .AllowExternalArtifact = false
155+ newRevision := "3.0.0"
156+ ea , err = applyExternalArtifact (eaKey , newRevision , "" )
157+ gt .Expect (err ).ToNot (HaveOccurred ())
115158
116- ea , err = applyExternalArtifact (eaKey , newRevision )
117- g .Expect (err ).ToNot (HaveOccurred ())
118-
119- g .Eventually (func () bool {
159+ gt .Eventually (func () bool {
120160 err = testEnv .Get (context .Background (), client .ObjectKeyFromObject (hr ), hr )
121161 if err != nil {
122162 return false
123163 }
124164 return apimeta .IsStatusConditionFalse (hr .Status .Conditions , meta .ReadyCondition )
125165 }, 5 * time .Second , time .Second ).Should (BeTrue ())
126166
127- g .Expect (apimeta .IsStatusConditionTrue (hr .Status .Conditions , meta .StalledCondition )).Should (BeTrue ())
167+ gt .Expect (apimeta .IsStatusConditionTrue (hr .Status .Conditions , meta .StalledCondition )).Should (BeTrue ())
128168 readyCondition := apimeta .FindStatusCondition (hr .Status .Conditions , meta .ReadyCondition )
129- g .Expect (readyCondition .Reason ).To (Equal (aclv1 .AccessDeniedReason ))
169+ gt .Expect (readyCondition .Reason ).To (Equal (aclv1 .AccessDeniedReason ))
130170 })
131171
132172 t .Run ("uninstalls successfully" , func (t * testing.T ) {
173+ gt := NewWithT (t )
133174 err = k8sClient .Delete (context .Background (), hr )
134- g .Expect (err ).ToNot (HaveOccurred ())
175+ gt .Expect (err ).ToNot (HaveOccurred ())
135176
136- g .Eventually (func () bool {
177+ gt .Eventually (func () bool {
137178 err = testEnv .Get (context .Background (), client .ObjectKeyFromObject (hr ), hr )
138179 return err != nil && client .IgnoreNotFound (err ) == nil
139180 }, 5 * time .Second , time .Second ).Should (BeTrue (), "HelmRelease was not deleted" )
140181 })
141182}
142183
143- func applyExternalArtifact (objKey client.ObjectKey , revision string ) (* sourcev1.ExternalArtifact , error ) {
144- chart := testutil .BuildChart (testutil .ChartWithVersion (revision ))
184+ func applyExternalArtifact (objKey client.ObjectKey , aVersion , aDigest string ) (* sourcev1.ExternalArtifact , error ) {
185+ chart := testutil .BuildChart (testutil .ChartWithVersion (aVersion ))
145186 artifact , err := testutil .SaveChartAsArtifact (chart , digest .SHA256 , testServer .URL (), testServer .Root ())
146187 if err != nil {
147188 return nil , err
@@ -169,6 +210,9 @@ func applyExternalArtifact(objKey client.ObjectKey, revision string) (*sourcev1.
169210 }
170211
171212 ea .ManagedFields = nil
213+ if aDigest != "" {
214+ artifact .Revision = aDigest
215+ }
172216 ea .Status = sourcev1.ExternalArtifactStatus {
173217 Artifact : artifact ,
174218 Conditions : []metav1.Condition {
0 commit comments