@@ -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,73 @@ 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 _ , tt := range tests {
257
+ t .Run (tt .name , func (t * testing.T ) {
258
+ m := manager {
259
+ releaseName : tt .releaseName ,
260
+ namespace : tt .releaseNs ,
261
+ values : tt .values ,
262
+ chart : tt .chart ,
263
+ }
264
+ if got := m .isUpgrade (tt .deployedRelease ); got != tt .want {
265
+ t .Errorf ("manager.isUpgrade() = %v, want %v" , got , tt .want )
266
+ }
267
+ })
268
+ }
269
+ }
270
+
271
+ func newTestChart (t * testing.T , path string ) * cpb.Chart {
272
+ chart , err := lpb .Load (path )
273
+ assert .Nil (t , err )
274
+ return chart
275
+ }
276
+
277
+ func newTestRelease (chart * cpb.Chart , values map [string ]interface {}, name , namespace string ) * rpb.Release {
278
+ release := rpb .Mock (& rpb.MockReleaseOptions {
279
+ Name : name ,
280
+ Namespace : namespace ,
281
+ Chart : chart ,
282
+ Version : 1 ,
283
+ })
284
+ release .Config = values
285
+ return release
286
+ }
0 commit comments