@ -34,7 +34,7 @@ import (
"k8s.io/helm/pkg/version"
)
func TestDeployment Manifest ( t * testing . T ) {
func TestDeployment ( t * testing . T ) {
tests := [ ] struct {
name string
image string
@ -48,14 +48,10 @@ func TestDeploymentManifest(t *testing.T) {
}
for _ , tt := range tests {
o , err := Deploymen tManifes t( & Options { Namespace : v1 . NamespaceDefault , ImageSpec : tt . image , UseCanary : tt . canary } )
dep , err := Deploymen t( & Options { Namespace : v1 . NamespaceDefault , ImageSpec : tt . image , UseCanary : tt . canary } )
if err != nil {
t . Fatalf ( "%s: error %q" , tt . name , err )
}
var dep v1beta1 . Deployment
if err := yaml . Unmarshal ( [ ] byte ( o ) , & dep ) ; err != nil {
t . Fatalf ( "%s: error %q" , tt . name , err )
}
if got := dep . Spec . Template . Spec . Containers [ 0 ] . Image ; got != tt . expect {
t . Errorf ( "%s: expected image %q, got %q" , tt . name , tt . expect , got )
@ -71,7 +67,7 @@ func TestDeploymentManifest(t *testing.T) {
}
}
func TestDeployment Manifest ForServiceAccount( t * testing . T ) {
func TestDeployment ForServiceAccount( t * testing . T ) {
tests := [ ] struct {
name string
image string
@ -84,22 +80,18 @@ func TestDeploymentManifestForServiceAccount(t *testing.T) {
{ "withoutSA" , "" , false , "gcr.io/kubernetes-helm/tiller:latest" , "IfNotPresent" , "" } ,
}
for _ , tt := range tests {
o , err := Deploymen tManifes t( & Options { Namespace : v1 . NamespaceDefault , ImageSpec : tt . image , UseCanary : tt . canary , ServiceAccount : tt . serviceAccount } )
d , err := Deploymen t( & Options { Namespace : v1 . NamespaceDefault , ImageSpec : tt . image , UseCanary : tt . canary , ServiceAccount : tt . serviceAccount } )
if err != nil {
t . Fatalf ( "%s: error %q" , tt . name , err )
}
var d v1beta1 . Deployment
if err := yaml . Unmarshal ( [ ] byte ( o ) , & d ) ; err != nil {
t . Fatalf ( "%s: error %q" , tt . name , err )
}
if got := d . Spec . Template . Spec . ServiceAccountName ; got != tt . serviceAccount {
t . Errorf ( "%s: expected service account value %q, got %q" , tt . name , tt . serviceAccount , got )
}
}
}
func TestDeployment Manifest _WithTLS( t * testing . T ) {
func TestDeployment _WithTLS( t * testing . T ) {
tests := [ ] struct {
opts Options
name string
@ -126,15 +118,11 @@ func TestDeploymentManifest_WithTLS(t *testing.T) {
} ,
}
for _ , tt := range tests {
o , err := Deploymen tManifes t( & tt . opts )
d , err := Deploymen t( & tt . opts )
if err != nil {
t . Fatalf ( "%s: error %q" , tt . name , err )
}
var d v1beta1 . Deployment
if err := yaml . Unmarshal ( [ ] byte ( o ) , & d ) ; err != nil {
t . Fatalf ( "%s: error %q" , tt . name , err )
}
// verify environment variable in deployment reflect the use of tls being enabled.
if got := d . Spec . Template . Spec . Containers [ 0 ] . Env [ 2 ] . Value ; got != tt . verify {
t . Errorf ( "%s: expected tls verify env value %q, got %q" , tt . name , tt . verify , got )
@ -146,14 +134,7 @@ func TestDeploymentManifest_WithTLS(t *testing.T) {
}
func TestServiceManifest ( t * testing . T ) {
o , err := ServiceManifest ( v1 . NamespaceDefault )
if err != nil {
t . Fatalf ( "error %q" , err )
}
var svc v1 . Service
if err := yaml . Unmarshal ( [ ] byte ( o ) , & svc ) ; err != nil {
t . Fatalf ( "error %q" , err )
}
svc := Service ( v1 . NamespaceDefault )
if got := svc . ObjectMeta . Namespace ; got != v1 . NamespaceDefault {
t . Errorf ( "expected namespace %s, got %s" , v1 . NamespaceDefault , got )
@ -161,7 +142,7 @@ func TestServiceManifest(t *testing.T) {
}
func TestSecretManifest ( t * testing . T ) {
o , err := Secre tManifes t( & Options {
o bj , err := Secre t( & Options {
VerifyTLS : true ,
EnableTLS : true ,
Namespace : v1 . NamespaceDefault ,
@ -174,11 +155,6 @@ func TestSecretManifest(t *testing.T) {
t . Fatalf ( "error %q" , err )
}
var obj v1 . Secret
if err := yaml . Unmarshal ( [ ] byte ( o ) , & obj ) ; err != nil {
t . Fatalf ( "error %q" , err )
}
if got := obj . ObjectMeta . Namespace ; got != v1 . NamespaceDefault {
t . Errorf ( "expected namespace %s, got %s" , v1 . NamespaceDefault , got )
}
@ -335,13 +311,13 @@ func TestInstall_canary(t *testing.T) {
func TestUpgrade ( t * testing . T ) {
image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
serviceAccount := "newServiceAccount"
existingDeployment , _ := d eployment( & Options {
existingDeployment , _ := generateD eployment( & Options {
Namespace : v1 . NamespaceDefault ,
ImageSpec : "imageToReplace:v1.0.0" ,
ServiceAccount : "serviceAccountToReplace" ,
UseCanary : false ,
} )
existingService := s ervice( v1 . NamespaceDefault )
existingService := generateS ervice( v1 . NamespaceDefault )
fc := & fake . Clientset { }
fc . AddReactor ( "get" , "deployments" , func ( action testcore . Action ) ( bool , runtime . Object , error ) {
@ -376,7 +352,7 @@ func TestUpgrade(t *testing.T) {
func TestUpgrade_serviceNotFound ( t * testing . T ) {
image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
existingDeployment , _ := d eployment( & Options {
existingDeployment , _ := generateD eployment( & Options {
Namespace : v1 . NamespaceDefault ,
ImageSpec : "imageToReplace" ,
UseCanary : false ,
@ -419,13 +395,13 @@ func TestUpgrade_serviceNotFound(t *testing.T) {
func TestUgrade_newerVersion ( t * testing . T ) {
image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
serviceAccount := "newServiceAccount"
existingDeployment , _ := d eployment( & Options {
existingDeployment , _ := generateD eployment( & Options {
Namespace : v1 . NamespaceDefault ,
ImageSpec : "imageToReplace:v100.5.0" ,
ServiceAccount : "serviceAccountToReplace" ,
UseCanary : false ,
} )
existingService := s ervice( v1 . NamespaceDefault )
existingService := generateS ervice( v1 . NamespaceDefault )
fc := & fake . Clientset { }
fc . AddReactor ( "get" , "deployments" , func ( action testcore . Action ) ( bool , runtime . Object , error ) {
@ -479,13 +455,13 @@ func TestUgrade_newerVersion(t *testing.T) {
func TestUpgrade_identical ( t * testing . T ) {
image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
serviceAccount := "newServiceAccount"
existingDeployment , _ := d eployment( & Options {
existingDeployment , _ := generateD eployment( & Options {
Namespace : v1 . NamespaceDefault ,
ImageSpec : "imageToReplace:v2.0.0" ,
ServiceAccount : "serviceAccountToReplace" ,
UseCanary : false ,
} )
existingService := s ervice( v1 . NamespaceDefault )
existingService := generateS ervice( v1 . NamespaceDefault )
fc := & fake . Clientset { }
fc . AddReactor ( "get" , "deployments" , func ( action testcore . Action ) ( bool , runtime . Object , error ) {
@ -520,13 +496,13 @@ func TestUpgrade_identical(t *testing.T) {
func TestUpgrade_canaryClient ( t * testing . T ) {
image := "gcr.io/kubernetes-helm/tiller:canary"
serviceAccount := "newServiceAccount"
existingDeployment , _ := d eployment( & Options {
existingDeployment , _ := generateD eployment( & Options {
Namespace : v1 . NamespaceDefault ,
ImageSpec : "imageToReplace:v1.0.0" ,
ServiceAccount : "serviceAccountToReplace" ,
UseCanary : false ,
} )
existingService := s ervice( v1 . NamespaceDefault )
existingService := generateS ervice( v1 . NamespaceDefault )
fc := & fake . Clientset { }
fc . AddReactor ( "get" , "deployments" , func ( action testcore . Action ) ( bool , runtime . Object , error ) {
@ -561,13 +537,13 @@ func TestUpgrade_canaryClient(t *testing.T) {
func TestUpgrade_canaryServer ( t * testing . T ) {
image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
serviceAccount := "newServiceAccount"
existingDeployment , _ := d eployment( & Options {
existingDeployment , _ := generateD eployment( & Options {
Namespace : v1 . NamespaceDefault ,
ImageSpec : "imageToReplace:canary" ,
ServiceAccount : "serviceAccountToReplace" ,
UseCanary : false ,
} )
existingService := s ervice( v1 . NamespaceDefault )
existingService := generateS ervice( v1 . NamespaceDefault )
fc := & fake . Clientset { }
fc . AddReactor ( "get" , "deployments" , func ( action testcore . Action ) ( bool , runtime . Object , error ) {
@ -607,7 +583,8 @@ func tlsTestFile(t *testing.T, path string) string {
}
return path
}
func TestDeploymentManifest_WithNodeSelectors ( t * testing . T ) {
func TestDeployment_WithNodeSelectors ( t * testing . T ) {
tests := [ ] struct {
opts Options
name string
@ -631,15 +608,11 @@ func TestDeploymentManifest_WithNodeSelectors(t *testing.T) {
} ,
}
for _ , tt := range tests {
o , err := Deploymen tManifes t( & tt . opts )
d , err := Deploymen t( & tt . opts )
if err != nil {
t . Fatalf ( "%s: error %q" , tt . name , err )
}
var d v1beta1 . Deployment
if err := yaml . Unmarshal ( [ ] byte ( o ) , & d ) ; err != nil {
t . Fatalf ( "%s: error %q" , tt . name , err )
}
// Verify that environment variables in Deployment reflect the use of TLS being enabled.
got := d . Spec . Template . Spec . NodeSelector
for k , v := range tt . expect {
@ -649,7 +622,8 @@ func TestDeploymentManifest_WithNodeSelectors(t *testing.T) {
}
}
}
func TestDeploymentManifest_WithSetValues ( t * testing . T ) {
func TestDeployment_WithSetValues ( t * testing . T ) {
tests := [ ] struct {
opts Options
name string
@ -676,11 +650,17 @@ func TestDeploymentManifest_WithSetValues(t *testing.T) {
} ,
}
for _ , tt := range tests {
o , err := Deploymen tManifes t( & tt . opts )
d , err := Deploymen t( & tt . opts )
if err != nil {
t . Fatalf ( "%s: error %q" , tt . name , err )
}
values , err := chartutil . ReadValues ( [ ] byte ( o ) )
o , err := yaml . Marshal ( d )
if err != nil {
t . Errorf ( "Error marshaling Deployment: %s" , err )
}
values , err := chartutil . ReadValues ( o )
if err != nil {
t . Errorf ( "Error converting Deployment manifest to Values: %s" , err )
}