예제 #1
0
func TestInitCmd_dryRun(t *testing.T) {
	// This is purely defensive in this case.
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	dbg := flagDebug
	flagDebug = true
	defer func() {
		os.Remove(home)
		flagDebug = dbg
	}()

	var buf bytes.Buffer
	fake := testclient.Fake{}
	cmd := &initCmd{
		out:        &buf,
		home:       helmpath.Home(home),
		kubeClient: fake.Extensions(),
		clientOnly: true,
		dryRun:     true,
	}
	if err := cmd.run(); err != nil {
		t.Fatal(err)
	}
	if len(fake.Actions()) != 0 {
		t.Error("expected no server calls")
	}

	var y map[string]interface{}
	if err := yaml.Unmarshal(buf.Bytes(), &y); err != nil {
		t.Errorf("Expected parseable YAML, got %q\n\t%s", buf.String(), err)
	}
}
예제 #2
0
파일: install_test.go 프로젝트: slack/helm
func TestInstall_canary(t *testing.T) {
	fake := testclient.Fake{}
	fake.AddReactor("create", "deployments", func(action testclient.Action) (bool, runtime.Object, error) {
		obj := action.(testclient.CreateAction).GetObject().(*extensions.Deployment)
		i := obj.Spec.Template.Spec.Containers[0].Image
		if i != "gcr.io/kubernetes-helm/tiller:canary" {
			t.Errorf("expected canary image, got '%s'", i)
		}
		return true, obj, nil
	})

	err := Install(fake.Extensions(), "default", "", true, false)
	if err != nil {
		t.Errorf("unexpected error: %#+v", err)
	}
}
예제 #3
0
파일: init_test.go 프로젝트: slack/helm
func TestInitCmd_clientOnly(t *testing.T) {
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(home)

	var buf bytes.Buffer
	fake := testclient.Fake{}
	cmd := &initCmd{out: &buf, home: helmpath.Home(home), kubeClient: fake.Extensions(), clientOnly: true}
	if err := cmd.run(); err != nil {
		t.Errorf("expected error: %v", err)
	}
	if len(fake.Actions()) != 0 {
		t.Error("expected client call")
	}
	expected := "Not installing tiller due to 'client-only' flag having been set"
	if !strings.Contains(buf.String(), expected) {
		t.Errorf("expected %q, got %q", expected, buf.String())
	}
}
예제 #4
0
파일: init_test.go 프로젝트: slack/helm
func TestInitCmd_exsits(t *testing.T) {
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(home)

	var buf bytes.Buffer
	fake := testclient.Fake{}
	fake.AddReactor("*", "*", func(action testclient.Action) (bool, runtime.Object, error) {
		return true, nil, errors.NewAlreadyExists(api.Resource("deployments"), "1")
	})
	cmd := &initCmd{out: &buf, home: helmpath.Home(home), kubeClient: fake.Extensions()}
	if err := cmd.run(); err != nil {
		t.Errorf("expected error: %v", err)
	}
	expected := "Warning: Tiller is already installed in the cluster. (Use --client-only to suppress this message.)"
	if !strings.Contains(buf.String(), expected) {
		t.Errorf("expected %q, got %q", expected, buf.String())
	}
}
예제 #5
0
파일: init_test.go 프로젝트: slack/helm
func TestInitCmd(t *testing.T) {
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(home)

	var buf bytes.Buffer
	fake := testclient.Fake{}
	cmd := &initCmd{out: &buf, home: helmpath.Home(home), kubeClient: fake.Extensions()}
	if err := cmd.run(); err != nil {
		t.Errorf("expected error: %v", err)
	}
	actions := fake.Actions()
	if action, ok := actions[0].(testclient.CreateAction); !ok || action.GetResource() != "deployments" {
		t.Errorf("unexpected action: %v, expected create deployment", actions[0])
	}
	expected := "Tiller (the helm server side component) has been installed into your Kubernetes Cluster."
	if !strings.Contains(buf.String(), expected) {
		t.Errorf("expected %q, got %q", expected, buf.String())
	}
}
예제 #6
0
파일: install_test.go 프로젝트: slack/helm
func TestInstall(t *testing.T) {
	image := "gcr.io/kubernetes-helm/tiller:v2.0.0"

	fake := testclient.Fake{}
	fake.AddReactor("create", "deployments", func(action testclient.Action) (bool, runtime.Object, error) {
		obj := action.(testclient.CreateAction).GetObject().(*extensions.Deployment)
		l := obj.GetLabels()
		if reflect.DeepEqual(l, map[string]string{"app": "helm"}) {
			t.Errorf("expected labels = '', got '%s'", l)
		}
		i := obj.Spec.Template.Spec.Containers[0].Image
		if i != image {
			t.Errorf("expected image = '%s', got '%s'", image, i)
		}
		return true, obj, nil
	})

	err := Install(fake.Extensions(), "default", image, false, false)
	if err != nil {
		t.Errorf("unexpected error: %#+v", err)
	}
}