@@ -17,16 +17,17 @@ package release
17
17
import (
18
18
"testing"
19
19
20
- "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured "
21
- apitypes "k8s.io/apimachinery/ pkg/types "
22
- "k8s.io/cli-runtime/ pkg/resource "
23
-
20
+ "github.com/stretchr/testify/assert "
21
+ cpb "helm.sh/helm/v3/ pkg/chart "
22
+ lpb "helm.sh/helm/v3/ pkg/chart/loader "
23
+ rpb "helm.sh/helm/v3/pkg/release"
24
24
appsv1 "k8s.io/api/apps/v1"
25
25
v1 "k8s.io/api/core/v1"
26
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
-
28
- "github.com/stretchr/testify/assert"
27
+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
29
28
"k8s.io/apimachinery/pkg/runtime"
29
+ apitypes "k8s.io/apimachinery/pkg/types"
30
+ "k8s.io/cli-runtime/pkg/resource"
30
31
)
31
32
32
33
func newTestUnstructured (containers []interface {}) * unstructured.Unstructured {
@@ -213,3 +214,72 @@ func TestManagerGenerateStrategicMergePatch(t *testing.T) {
213
214
assert .Equal (t , test .patch , string (diff ))
214
215
}
215
216
}
217
+
218
+ func TestManagerisUpgrade (t * testing.T ) {
219
+ tests := []struct {
220
+ name string
221
+ releaseName string
222
+ releaseNs string
223
+ values map [string ]interface {}
224
+ chart * cpb.Chart
225
+ deployedRelease * rpb.Release
226
+ want bool
227
+ }{
228
+ {
229
+ name : "ok" ,
230
+ releaseName : "deployed" ,
231
+ releaseNs : "deployed-ns" ,
232
+ values : map [string ]interface {}{"key" : "value" },
233
+ chart : newTestChart (t , "./testdata/simple" ),
234
+ deployedRelease : newTestRelease (newTestChart (t , "./testdata/simple" ), map [string ]interface {}{"key" : "value" }, "deployed" , "deployed-ns" ),
235
+ want : false ,
236
+ },
237
+ {
238
+ name : "different chart" ,
239
+ releaseName : "deployed" ,
240
+ releaseNs : "deployed-ns" ,
241
+ values : map [string ]interface {}{"key" : "value" },
242
+ chart : newTestChart (t , "./testdata/simple" ),
243
+ deployedRelease : newTestRelease (newTestChart (t , "./testdata/simpledf" ), map [string ]interface {}{"key" : "value" }, "deployed" , "deployed-ns" ),
244
+ want : true ,
245
+ },
246
+ {
247
+ name : "different values" ,
248
+ releaseName : "deployed" ,
249
+ releaseNs : "deployed-ns" ,
250
+ values : map [string ]interface {}{"key" : "1" },
251
+ chart : newTestChart (t , "./testdata/simple" ),
252
+ deployedRelease : newTestRelease (newTestChart (t , "./testdata/simple" ), map [string ]interface {}{"key" : "" }, "deployed" , "deployed-ns" ),
253
+ want : true ,
254
+ },
255
+ }
256
+ for _ , test := range tests {
257
+ t .Run (test .name , func (t * testing.T ) {
258
+ m := manager {
259
+ releaseName : test .releaseName ,
260
+ namespace : test .releaseNs ,
261
+ values : test .values ,
262
+ chart : test .chart ,
263
+ }
264
+ isUpgrade := m .isUpgrade (test .deployedRelease )
265
+ assert .Equal (t , test .want , isUpgrade )
266
+ })
267
+ }
268
+ }
269
+
270
+ func newTestChart (t * testing.T , path string ) * cpb.Chart {
271
+ chart , err := lpb .Load (path )
272
+ assert .Nil (t , err )
273
+ return chart
274
+ }
275
+
276
+ func newTestRelease (chart * cpb.Chart , values map [string ]interface {}, name , namespace string ) * rpb.Release {
277
+ release := rpb .Mock (& rpb.MockReleaseOptions {
278
+ Name : name ,
279
+ Namespace : namespace ,
280
+ Chart : chart ,
281
+ Version : 1 ,
282
+ })
283
+ release .Config = values
284
+ return release
285
+ }
0 commit comments