github.com/felipejfc/helm@v2.1.2+incompatible/cmd/helm/installer/install_test.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors All rights reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package installer // import "k8s.io/helm/cmd/helm/installer"
    18  
    19  import (
    20  	"reflect"
    21  	"testing"
    22  
    23  	"github.com/ghodss/yaml"
    24  	"k8s.io/kubernetes/pkg/api"
    25  	"k8s.io/kubernetes/pkg/apis/extensions"
    26  	"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
    27  	testcore "k8s.io/kubernetes/pkg/client/testing/core"
    28  	"k8s.io/kubernetes/pkg/runtime"
    29  
    30  	"k8s.io/helm/pkg/version"
    31  )
    32  
    33  func TestDeploymentManifest(t *testing.T) {
    34  
    35  	tests := []struct {
    36  		name   string
    37  		image  string
    38  		canary bool
    39  		expect string
    40  	}{
    41  		{"default", "", false, "gcr.io/kubernetes-helm/tiller:" + version.Version},
    42  		{"canary", "example.com/tiller", true, "gcr.io/kubernetes-helm/tiller:canary"},
    43  		{"custom", "example.com/tiller:latest", false, "example.com/tiller:latest"},
    44  	}
    45  
    46  	for _, tt := range tests {
    47  
    48  		o, err := DeploymentManifest(api.NamespaceDefault, tt.image, tt.canary)
    49  		if err != nil {
    50  			t.Fatalf("%s: error %q", tt.name, err)
    51  		}
    52  		var dep extensions.Deployment
    53  		if err := yaml.Unmarshal([]byte(o), &dep); err != nil {
    54  			t.Fatalf("%s: error %q", tt.name, err)
    55  		}
    56  
    57  		if got := dep.Spec.Template.Spec.Containers[0].Image; got != tt.expect {
    58  			t.Errorf("%s: expected image %q, got %q", tt.name, tt.expect, got)
    59  		}
    60  	}
    61  }
    62  
    63  func TestInstall(t *testing.T) {
    64  	image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
    65  
    66  	fake := fake.NewSimpleClientset()
    67  	fake.AddReactor("create", "deployments", func(action testcore.Action) (bool, runtime.Object, error) {
    68  		obj := action.(testcore.CreateAction).GetObject().(*extensions.Deployment)
    69  		l := obj.GetLabels()
    70  		if reflect.DeepEqual(l, map[string]string{"app": "helm"}) {
    71  			t.Errorf("expected labels = '', got '%s'", l)
    72  		}
    73  		i := obj.Spec.Template.Spec.Containers[0].Image
    74  		if i != image {
    75  			t.Errorf("expected image = '%s', got '%s'", image, i)
    76  		}
    77  		return true, obj, nil
    78  	})
    79  
    80  	err := Install(fake.Extensions(), api.NamespaceDefault, image, false, false)
    81  	if err != nil {
    82  		t.Errorf("unexpected error: %#+v", err)
    83  	}
    84  }
    85  
    86  func TestInstall_canary(t *testing.T) {
    87  	fake := fake.NewSimpleClientset()
    88  	fake.AddReactor("create", "deployments", func(action testcore.Action) (bool, runtime.Object, error) {
    89  		obj := action.(testcore.CreateAction).GetObject().(*extensions.Deployment)
    90  		i := obj.Spec.Template.Spec.Containers[0].Image
    91  		if i != "gcr.io/kubernetes-helm/tiller:canary" {
    92  			t.Errorf("expected canary image, got '%s'", i)
    93  		}
    94  		return true, obj, nil
    95  	})
    96  
    97  	err := Install(fake.Extensions(), api.NamespaceDefault, "", true, false)
    98  	if err != nil {
    99  		t.Errorf("unexpected error: %#+v", err)
   100  	}
   101  }