ref(tiller): move test only code into test file

pull/1309/head
Adam Reese 9 years ago
parent b7abaa37e0
commit a50e2cc950

@ -16,10 +16,6 @@ limitations under the License.
package main
import (
"sort"
)
// SortOrder is an ordering of Kinds.
type SortOrder []string
@ -28,48 +24,3 @@ var InstallOrder SortOrder = []string{"Namespace", "Secret", "ConfigMap", "Persi
// UninstallOrder is the order in which manifests should be uninstalled (by Kind)
var UninstallOrder SortOrder = []string{"Service", "Pod", "ReplicationController", "Deployment", "DaemonSet", "ConfigMap", "Secret", "PersistentVolume", "ServiceAccount", "Ingress", "Job", "Namespace"}
// sortByKind does an in-place sort of manifests by Kind.
//
// Results are sorted by 'ordering'
func sortByKind(manifests []manifest, ordering SortOrder) []manifest {
ks := newKindSorter(manifests, ordering)
sort.Sort(ks)
return ks.manifests
}
type kindSorter struct {
ordering map[string]int
manifests []manifest
}
func newKindSorter(m []manifest, s SortOrder) *kindSorter {
o := make(map[string]int, len(s))
for v, k := range s {
o[k] = v
}
return &kindSorter{
manifests: m,
ordering: o,
}
}
func (k *kindSorter) Len() int { return len(k.manifests) }
func (k *kindSorter) Swap(i, j int) { k.manifests[i], k.manifests[j] = k.manifests[j], k.manifests[i] }
func (k *kindSorter) Less(i, j int) bool {
a := k.manifests[i]
b := k.manifests[j]
first, ok := k.ordering[a.head.Kind]
if !ok {
// Unknown is always last
return false
}
second, ok := k.ordering[b.head.Kind]
if !ok {
return true
}
return first < second
}

@ -17,9 +17,55 @@ limitations under the License.
package main
import (
"sort"
"testing"
)
func newKindSorter(m []manifest, s SortOrder) *kindSorter {
o := make(map[string]int, len(s))
for v, k := range s {
o[k] = v
}
return &kindSorter{
manifests: m,
ordering: o,
}
}
// sortByKind does an in-place sort of manifests by Kind.
//
// Results are sorted by 'ordering'
func sortByKind(manifests []manifest, ordering SortOrder) []manifest {
ks := newKindSorter(manifests, ordering)
sort.Sort(ks)
return ks.manifests
}
type kindSorter struct {
ordering map[string]int
manifests []manifest
}
func (k *kindSorter) Len() int { return len(k.manifests) }
func (k *kindSorter) Swap(i, j int) { k.manifests[i], k.manifests[j] = k.manifests[j], k.manifests[i] }
func (k *kindSorter) Less(i, j int) bool {
a := k.manifests[i]
b := k.manifests[j]
first, ok := k.ordering[a.head.Kind]
if !ok {
// Unknown is always last
return false
}
second, ok := k.ordering[b.head.Kind]
if !ok {
return true
}
return first < second
}
func TestKindSorter(t *testing.T) {
manifests := []manifest{
{

@ -25,11 +25,9 @@ import (
"sort"
"strings"
"google.golang.org/grpc/metadata"
"github.com/ghodss/yaml"
"github.com/technosophos/moniker"
ctx "golang.org/x/net/context"
"google.golang.org/grpc/metadata"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/helm/cmd/tiller/environment"
@ -702,12 +700,6 @@ func (s *releaseServer) renderResources(ch *chart.Chart, values chartutil.Values
return hooks, b, notes, nil
}
// validateYAML checks to see if YAML is well-formed.
func validateYAML(data string) error {
b := map[string]interface{}{}
return yaml.Unmarshal([]byte(data), b)
}
func (s *releaseServer) recordRelease(r *release.Release, reuse bool) {
if reuse {
if err := s.env.Releases.Update(r); err != nil {

Loading…
Cancel
Save