1515package  release
1616
1717import  (
18+ 	"io/ioutil" 
1819	"testing" 
1920
2021	"github.com/stretchr/testify/assert" 
22+ 	"helm.sh/helm/v3/pkg/action" 
2123	cpb "helm.sh/helm/v3/pkg/chart" 
2224	lpb "helm.sh/helm/v3/pkg/chart/loader" 
25+ 	"helm.sh/helm/v3/pkg/chartutil" 
26+ 	kubefake "helm.sh/helm/v3/pkg/kube/fake" 
2327	rpb "helm.sh/helm/v3/pkg/release" 
28+ 	"helm.sh/helm/v3/pkg/storage" 
29+ 	"helm.sh/helm/v3/pkg/storage/driver" 
2430	appsv1 "k8s.io/api/apps/v1" 
2531	v1 "k8s.io/api/core/v1" 
2632	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 
@@ -247,11 +253,20 @@ func TestManagerisUpgrade(t *testing.T) {
247253			name :            "different values" ,
248254			releaseName :     "deployed" ,
249255			releaseNs :       "deployed-ns" ,
250- 			values :          map [string ]interface {}{"key" : "1" },
256+ 			values :          map [string ]interface {}{"key" : "1" ,  "int" :  int32 ( 1 ) },
251257			chart :           newTestChart (t , "./testdata/simple" ),
252- 			deployedRelease : newTestRelease (newTestChart (t , "./testdata/simple" ), map [string ]interface {}{"key" : "" }, "deployed" , "deployed-ns" ),
258+ 			deployedRelease : newTestRelease (newTestChart (t , "./testdata/simple" ), map [string ]interface {}{"key" : "" ,  "int" :  int64 ( 1 ) }, "deployed" , "deployed-ns" ),
253259			want :            true ,
254260		},
261+ 		{
262+ 			name :            "nil values" ,
263+ 			releaseName :     "deployed" ,
264+ 			releaseNs :       "deployed-ns" ,
265+ 			values :          nil ,
266+ 			chart :           newTestChart (t , "./testdata/simple" ),
267+ 			deployedRelease : newTestRelease (newTestChart (t , "./testdata/simple" ), map [string ]interface {}{}, "deployed" , "deployed-ns" ),
268+ 			want :            false ,
269+ 		},
255270	}
256271	for  _ , test  :=  range  tests  {
257272		t .Run (test .name , func (t  * testing.T ) {
@@ -260,9 +275,17 @@ func TestManagerisUpgrade(t *testing.T) {
260275				namespace :   test .releaseNs ,
261276				values :      test .values ,
262277				chart :       test .chart ,
278+ 				actionConfig : & action.Configuration {
279+ 					Releases :     storage .Init (driver .NewMemory ()),
280+ 					KubeClient :   & kubefake.FailingKubeClient {PrintingKubeClient : kubefake.PrintingKubeClient {Out : ioutil .Discard }},
281+ 					Capabilities : chartutil .DefaultCapabilities ,
282+ 					Log :          t .Logf ,
283+ 				},
263284			}
264- 			isUpgrade  :=  m .isUpgrade (test .deployedRelease )
285+ 			assert .Equal (t , nil , m .actionConfig .Releases .Create (test .deployedRelease ))
286+ 			isUpgrade , err  :=  m .isUpgrade (test .deployedRelease )
265287			assert .Equal (t , test .want , isUpgrade )
288+ 			assert .Equal (t , nil , err )
266289		})
267290	}
268291}
@@ -273,13 +296,14 @@ func newTestChart(t *testing.T, path string) *cpb.Chart {
273296	return  chart 
274297}
275298
276- func  newTestRelease (chart  * cpb.Chart , values  map [string ]interface {}, name , namespace  string ) * rpb.Release  {
299+ func  newTestRelease (chart  * cpb.Chart , values  map [string ]interface {}, name , namespace  string ) * rpb.Release  {  // nolint: unparam 
277300	release  :=  rpb .Mock (& rpb.MockReleaseOptions {
278301		Name :      name ,
279302		Namespace : namespace ,
280- 		Chart :     chart ,
281303		Version :   1 ,
304+ 		Chart :     chart ,
282305	})
306+ 
283307	release .Config  =  values 
284308	return  release 
285309}
0 commit comments