github.com/strongmonkey/helm@v2.7.2+incompatible/cmd/helm/installer/uninstall_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  	"testing"
    21  
    22  	apierrors "k8s.io/apimachinery/pkg/api/errors"
    23  	"k8s.io/apimachinery/pkg/runtime"
    24  	"k8s.io/apimachinery/pkg/runtime/schema"
    25  	testcore "k8s.io/client-go/testing"
    26  	"k8s.io/kubernetes/pkg/api"
    27  	"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
    28  )
    29  
    30  func TestUninstall(t *testing.T) {
    31  	fc := &fake.Clientset{}
    32  	opts := &Options{Namespace: api.NamespaceDefault}
    33  	if err := Uninstall(fc, opts); err != nil {
    34  		t.Errorf("unexpected error: %#+v", err)
    35  	}
    36  
    37  	if actions := fc.Actions(); len(actions) != 7 {
    38  		t.Errorf("unexpected actions: %v, expected 7 actions got %d", actions, len(actions))
    39  	}
    40  }
    41  
    42  func TestUninstall_serviceNotFound(t *testing.T) {
    43  	fc := &fake.Clientset{}
    44  	fc.AddReactor("delete", "services", func(action testcore.Action) (bool, runtime.Object, error) {
    45  		return true, nil, apierrors.NewNotFound(schema.GroupResource{Resource: "services"}, "1")
    46  	})
    47  
    48  	opts := &Options{Namespace: api.NamespaceDefault}
    49  	if err := Uninstall(fc, opts); err != nil {
    50  		t.Errorf("unexpected error: %#+v", err)
    51  	}
    52  
    53  	if actions := fc.Actions(); len(actions) != 7 {
    54  		t.Errorf("unexpected actions: %v, expected 7 actions got %d", actions, len(actions))
    55  	}
    56  }
    57  
    58  func TestUninstall_deploymentNotFound(t *testing.T) {
    59  	fc := &fake.Clientset{}
    60  	fc.AddReactor("delete", "deployments", func(action testcore.Action) (bool, runtime.Object, error) {
    61  		return true, nil, apierrors.NewNotFound(api.Resource("deployments"), "1")
    62  	})
    63  
    64  	opts := &Options{Namespace: api.NamespaceDefault}
    65  	if err := Uninstall(fc, opts); err != nil {
    66  		t.Errorf("unexpected error: %#+v", err)
    67  	}
    68  
    69  	if actions := fc.Actions(); len(actions) != 7 {
    70  		t.Errorf("unexpected actions: %v, expected 7 actions got %d", actions, len(actions))
    71  	}
    72  }
    73  
    74  func TestUninstall_secretNotFound(t *testing.T) {
    75  	fc := &fake.Clientset{}
    76  	fc.AddReactor("delete", "secrets", func(action testcore.Action) (bool, runtime.Object, error) {
    77  		return true, nil, apierrors.NewNotFound(api.Resource("secrets"), "1")
    78  	})
    79  
    80  	opts := &Options{Namespace: api.NamespaceDefault}
    81  	if err := Uninstall(fc, opts); err != nil {
    82  		t.Errorf("unexpected error: %#+v", err)
    83  	}
    84  
    85  	if actions := fc.Actions(); len(actions) != 7 {
    86  		t.Errorf("unexpected actions: %v, expect 7 actions got %d", actions, len(actions))
    87  	}
    88  }