github.com/sgoings/helm@v2.0.0-alpha.2.0.20170406211108-734e92851ac3+incompatible/pkg/tiller/kind_sorter_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 tiller 18 19 import ( 20 "bytes" 21 "testing" 22 23 util "k8s.io/helm/pkg/releaseutil" 24 ) 25 26 func TestKindSorter(t *testing.T) { 27 manifests := []manifest{ 28 { 29 name: "i", 30 content: "", 31 head: &util.SimpleHead{Kind: "ClusterRole"}, 32 }, 33 { 34 name: "j", 35 content: "", 36 head: &util.SimpleHead{Kind: "ClusterRoleBinding"}, 37 }, 38 { 39 name: "e", 40 content: "", 41 head: &util.SimpleHead{Kind: "ConfigMap"}, 42 }, 43 { 44 name: "u", 45 content: "", 46 head: &util.SimpleHead{Kind: "CronJob"}, 47 }, 48 { 49 name: "n", 50 content: "", 51 head: &util.SimpleHead{Kind: "DaemonSet"}, 52 }, 53 { 54 name: "r", 55 content: "", 56 head: &util.SimpleHead{Kind: "Deployment"}, 57 }, 58 { 59 name: "!", 60 content: "", 61 head: &util.SimpleHead{Kind: "HonkyTonkSet"}, 62 }, 63 { 64 name: "v", 65 content: "", 66 head: &util.SimpleHead{Kind: "Ingress"}, 67 }, 68 { 69 name: "t", 70 content: "", 71 head: &util.SimpleHead{Kind: "Job"}, 72 }, 73 { 74 name: "c", 75 content: "", 76 head: &util.SimpleHead{Kind: "LimitRange"}, 77 }, 78 { 79 name: "a", 80 content: "", 81 head: &util.SimpleHead{Kind: "Namespace"}, 82 }, 83 { 84 name: "f", 85 content: "", 86 head: &util.SimpleHead{Kind: "PersistentVolume"}, 87 }, 88 { 89 name: "g", 90 content: "", 91 head: &util.SimpleHead{Kind: "PersistentVolumeClaim"}, 92 }, 93 { 94 name: "o", 95 content: "", 96 head: &util.SimpleHead{Kind: "Pod"}, 97 }, 98 { 99 name: "q", 100 content: "", 101 head: &util.SimpleHead{Kind: "ReplicaSet"}, 102 }, 103 { 104 name: "p", 105 content: "", 106 head: &util.SimpleHead{Kind: "ReplicationController"}, 107 }, 108 { 109 name: "b", 110 content: "", 111 head: &util.SimpleHead{Kind: "ResourceQuota"}, 112 }, 113 { 114 name: "k", 115 content: "", 116 head: &util.SimpleHead{Kind: "Role"}, 117 }, 118 { 119 name: "l", 120 content: "", 121 head: &util.SimpleHead{Kind: "RoleBinding"}, 122 }, 123 { 124 name: "d", 125 content: "", 126 head: &util.SimpleHead{Kind: "Secret"}, 127 }, 128 { 129 name: "m", 130 content: "", 131 head: &util.SimpleHead{Kind: "Service"}, 132 }, 133 { 134 name: "h", 135 content: "", 136 head: &util.SimpleHead{Kind: "ServiceAccount"}, 137 }, 138 { 139 name: "s", 140 content: "", 141 head: &util.SimpleHead{Kind: "StatefulSet"}, 142 }, 143 } 144 145 for _, test := range []struct { 146 description string 147 order SortOrder 148 expected string 149 }{ 150 {"install", InstallOrder, "abcdefghijklmnopqrstuv!"}, 151 {"uninstall", UninstallOrder, "vmutsrqponlkjihgfedcba!"}, 152 } { 153 var buf bytes.Buffer 154 t.Run(test.description, func(t *testing.T) { 155 if got, want := len(test.expected), len(manifests); got != want { 156 t.Fatalf("Expected %d names in order, got %d", want, got) 157 } 158 defer buf.Reset() 159 for _, r := range sortByKind(manifests, test.order) { 160 buf.WriteString(r.name) 161 } 162 if got := buf.String(); got != test.expected { 163 t.Errorf("Expected %q, got %q", test.expected, got) 164 } 165 }) 166 } 167 }