mirror of https://github.com/helm/helm
reviewable/pr1155/r1
parent
de5365ec5c
commit
e25732284b
@ -1,33 +1,49 @@
|
|||||||
package driver
|
/*
|
||||||
|
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package driver // import "k8s.io/helm/pkg/storage/driver"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLabelsMatch(t *testing.T) {
|
func TestLabelsMatch(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
desc string
|
desc string
|
||||||
set1 labels
|
set1 labels
|
||||||
set2 labels
|
set2 labels
|
||||||
expect bool
|
expect bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"equal labels sets",
|
"equal labels sets",
|
||||||
labels(map[string]string{"KEY_A": "VAL_A", "KEY_B": "VAL_B"}),
|
labels(map[string]string{"KEY_A": "VAL_A", "KEY_B": "VAL_B"}),
|
||||||
labels(map[string]string{"KEY_A": "VAL_A", "KEY_B": "VAL_B"}),
|
labels(map[string]string{"KEY_A": "VAL_A", "KEY_B": "VAL_B"}),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"disjoint label sets",
|
"disjoint label sets",
|
||||||
labels(map[string]string{"KEY_C": "VAL_C", "KEY_D": "VAL_D"}),
|
labels(map[string]string{"KEY_C": "VAL_C", "KEY_D": "VAL_D"}),
|
||||||
labels(map[string]string{"KEY_A": "VAL_A", "KEY_B": "VAL_B"}),
|
labels(map[string]string{"KEY_A": "VAL_A", "KEY_B": "VAL_B"}),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if !tt.set1.match(tt.set2) && tt.expect {
|
if !tt.set1.match(tt.set2) && tt.expect {
|
||||||
t.Fatalf("Expected match '%s'\n", tt.desc)
|
t.Fatalf("Expected match '%s'\n", tt.desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,71 +1,87 @@
|
|||||||
package driver
|
/*
|
||||||
|
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package driver // import "k8s.io/helm/pkg/storage/driver"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
rspb "k8s.io/helm/pkg/proto/hapi/release"
|
rspb "k8s.io/helm/pkg/proto/hapi/release"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRecordsAdd(t *testing.T) {
|
func TestRecordsAdd(t *testing.T) {
|
||||||
rs := records([]*record{
|
rs := records([]*record{
|
||||||
newRecord("rls-a.v1", releaseStub("rls-a", 1, rspb.Status_SUPERSEDED)),
|
newRecord("rls-a.v1", releaseStub("rls-a", 1, rspb.Status_SUPERSEDED)),
|
||||||
newRecord("rls-a.v2", releaseStub("rls-a", 2, rspb.Status_DEPLOYED)),
|
newRecord("rls-a.v2", releaseStub("rls-a", 2, rspb.Status_DEPLOYED)),
|
||||||
})
|
})
|
||||||
|
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
desc string
|
desc string
|
||||||
key string
|
key string
|
||||||
ok bool
|
ok bool
|
||||||
rec *record
|
rec *record
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"add valid key",
|
"add valid key",
|
||||||
"rls-a.v3",
|
"rls-a.v3",
|
||||||
false,
|
false,
|
||||||
newRecord("rls-a.v3", releaseStub("rls-a", 3, rspb.Status_SUPERSEDED)),
|
newRecord("rls-a.v3", releaseStub("rls-a", 3, rspb.Status_SUPERSEDED)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"add already existing key",
|
"add already existing key",
|
||||||
"rls-a.v1",
|
"rls-a.v1",
|
||||||
true,
|
true,
|
||||||
newRecord("rls-a.v1", releaseStub("rls-a", 1, rspb.Status_DEPLOYED)),
|
newRecord("rls-a.v1", releaseStub("rls-a", 1, rspb.Status_DEPLOYED)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if err := rs.Add(tt.rec); err != nil {
|
if err := rs.Add(tt.rec); err != nil {
|
||||||
if !tt.ok {
|
if !tt.ok {
|
||||||
t.Fatalf("failed: %q: %s\n", tt.desc, err)
|
t.Fatalf("failed: %q: %s\n", tt.desc, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRecordsRemove(t *testing.T) {
|
func TestRecordsRemove(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
desc string
|
desc string
|
||||||
key string
|
key string
|
||||||
ok bool
|
ok bool
|
||||||
}{
|
}{
|
||||||
{"remove valid key", "rls-a.v1", false},
|
{"remove valid key", "rls-a.v1", false},
|
||||||
{"remove invalid key", "rls-a.v", true},
|
{"remove invalid key", "rls-a.v", true},
|
||||||
{"remove non-existant key", "rls-z.v1", true},
|
{"remove non-existant key", "rls-z.v1", true},
|
||||||
}
|
}
|
||||||
|
|
||||||
rs := records([]*record{
|
rs := records([]*record{
|
||||||
newRecord("rls-a.v1", releaseStub("rls-a", 1, rspb.Status_SUPERSEDED)),
|
newRecord("rls-a.v1", releaseStub("rls-a", 1, rspb.Status_SUPERSEDED)),
|
||||||
newRecord("rls-a.v2", releaseStub("rls-a", 2, rspb.Status_DEPLOYED)),
|
newRecord("rls-a.v2", releaseStub("rls-a", 2, rspb.Status_DEPLOYED)),
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if r := rs.Remove(tt.key); r == nil {
|
if r := rs.Remove(tt.key); r == nil {
|
||||||
if !tt.ok {
|
if !tt.ok {
|
||||||
t.Fatalf("Failed to %q (key = %s). Expected nil, got %s",
|
t.Fatalf("Failed to %q (key = %s). Expected nil, got %s",
|
||||||
tt.desc,
|
tt.desc,
|
||||||
tt.key,
|
tt.key,
|
||||||
r,
|
r,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,119 +1,135 @@
|
|||||||
package driver
|
/*
|
||||||
|
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package driver // import "k8s.io/helm/pkg/storage/driver"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
rspb "k8s.io/helm/pkg/proto/hapi/release"
|
rspb "k8s.io/helm/pkg/proto/hapi/release"
|
||||||
"k8s.io/kubernetes/pkg/client/unversioned"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
kberrs "k8s.io/kubernetes/pkg/api/errors"
|
kberrs "k8s.io/kubernetes/pkg/api/errors"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
)
|
)
|
||||||
|
|
||||||
func releaseStub(name string, vers int32, code rspb.Status_Code) *rspb.Release {
|
func releaseStub(name string, vers int32, code rspb.Status_Code) *rspb.Release {
|
||||||
return &rspb.Release{
|
return &rspb.Release{
|
||||||
Name: name,
|
Name: name,
|
||||||
Version: vers,
|
Version: vers,
|
||||||
Info: &rspb.Info{Status: &rspb.Status{Code: code}},
|
Info: &rspb.Info{Status: &rspb.Status{Code: code}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testKey(name string, vers int32) string {
|
func testKey(name string, vers int32) string {
|
||||||
return fmt.Sprintf("%s.v%d", name, vers)
|
return fmt.Sprintf("%s.v%d", name, vers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tsFixtureMemory(t *testing.T) *Memory {
|
func tsFixtureMemory(t *testing.T) *Memory {
|
||||||
hs := []*rspb.Release{
|
hs := []*rspb.Release{
|
||||||
// rls-a
|
// rls-a
|
||||||
releaseStub("rls-a", 4, rspb.Status_DEPLOYED),
|
releaseStub("rls-a", 4, rspb.Status_DEPLOYED),
|
||||||
releaseStub("rls-a", 1, rspb.Status_SUPERSEDED),
|
releaseStub("rls-a", 1, rspb.Status_SUPERSEDED),
|
||||||
releaseStub("rls-a", 3, rspb.Status_SUPERSEDED),
|
releaseStub("rls-a", 3, rspb.Status_SUPERSEDED),
|
||||||
releaseStub("rls-a", 2, rspb.Status_SUPERSEDED),
|
releaseStub("rls-a", 2, rspb.Status_SUPERSEDED),
|
||||||
// rls-b
|
// rls-b
|
||||||
releaseStub("rls-b", 4, rspb.Status_DEPLOYED),
|
releaseStub("rls-b", 4, rspb.Status_DEPLOYED),
|
||||||
releaseStub("rls-b", 1, rspb.Status_SUPERSEDED),
|
releaseStub("rls-b", 1, rspb.Status_SUPERSEDED),
|
||||||
releaseStub("rls-b", 3, rspb.Status_SUPERSEDED),
|
releaseStub("rls-b", 3, rspb.Status_SUPERSEDED),
|
||||||
releaseStub("rls-b", 2, rspb.Status_SUPERSEDED),
|
releaseStub("rls-b", 2, rspb.Status_SUPERSEDED),
|
||||||
}
|
}
|
||||||
|
|
||||||
mem := NewMemory()
|
mem := NewMemory()
|
||||||
for _, tt := range hs {
|
for _, tt := range hs {
|
||||||
err := mem.Create(testKey(tt.Name, tt.Version), tt)
|
err := mem.Create(testKey(tt.Name, tt.Version), tt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test setup failed to create: %s\n", err)
|
t.Fatalf("Test setup failed to create: %s\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mem
|
return mem
|
||||||
}
|
}
|
||||||
|
|
||||||
// newTestFixture initializes a MockConfigMapsInterface.
|
// newTestFixture initializes a MockConfigMapsInterface.
|
||||||
// ConfigMaps are created for each release provided.
|
// ConfigMaps are created for each release provided.
|
||||||
func newTestFixtureCfgMaps(t *testing.T, releases ...*rspb.Release) *ConfigMaps {
|
func newTestFixtureCfgMaps(t *testing.T, releases ...*rspb.Release) *ConfigMaps {
|
||||||
var mock MockConfigMapsInterface
|
var mock MockConfigMapsInterface
|
||||||
mock.Init(t, releases...)
|
mock.Init(t, releases...)
|
||||||
|
|
||||||
return NewConfigMaps(&mock)
|
return NewConfigMaps(&mock)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MockConfigMapsInterface mocks a kubernetes ConfigMapsInterface
|
// MockConfigMapsInterface mocks a kubernetes ConfigMapsInterface
|
||||||
type MockConfigMapsInterface struct {
|
type MockConfigMapsInterface struct {
|
||||||
unversioned.ConfigMapsInterface
|
unversioned.ConfigMapsInterface
|
||||||
|
|
||||||
objects map[string]*api.ConfigMap
|
objects map[string]*api.ConfigMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mock *MockConfigMapsInterface) Init(t *testing.T, releases ...*rspb.Release) {
|
func (mock *MockConfigMapsInterface) Init(t *testing.T, releases ...*rspb.Release) {
|
||||||
mock.objects = map[string]*api.ConfigMap{}
|
mock.objects = map[string]*api.ConfigMap{}
|
||||||
|
|
||||||
for _, rls := range releases {
|
for _, rls := range releases {
|
||||||
objkey := testKey(rls.Name, rls.Version)
|
objkey := testKey(rls.Name, rls.Version)
|
||||||
|
|
||||||
cfgmap, err := newConfigMapsObject(objkey, rls, nil)
|
cfgmap, err := newConfigMapsObject(objkey, rls, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create configmap: %s", err)
|
t.Fatalf("Failed to create configmap: %s", err)
|
||||||
}
|
}
|
||||||
mock.objects[objkey] = cfgmap
|
mock.objects[objkey] = cfgmap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mock *MockConfigMapsInterface) Get(name string) (*api.ConfigMap, error) {
|
func (mock *MockConfigMapsInterface) Get(name string) (*api.ConfigMap, error) {
|
||||||
object, ok := mock.objects[name]
|
object, ok := mock.objects[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, kberrs.NewNotFound(api.Resource("tests"), name)
|
return nil, kberrs.NewNotFound(api.Resource("tests"), name)
|
||||||
}
|
}
|
||||||
return object, nil
|
return object, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mock *MockConfigMapsInterface) List(opts api.ListOptions) (*api.ConfigMapList, error) {
|
func (mock *MockConfigMapsInterface) List(opts api.ListOptions) (*api.ConfigMapList, error) {
|
||||||
var list api.ConfigMapList
|
var list api.ConfigMapList
|
||||||
for _, cfgmap := range mock.objects {
|
for _, cfgmap := range mock.objects {
|
||||||
list.Items = append(list.Items, *cfgmap)
|
list.Items = append(list.Items, *cfgmap)
|
||||||
}
|
}
|
||||||
return &list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mock *MockConfigMapsInterface) Create(cfgmap *api.ConfigMap) (*api.ConfigMap, error) {
|
func (mock *MockConfigMapsInterface) Create(cfgmap *api.ConfigMap) (*api.ConfigMap, error) {
|
||||||
name := cfgmap.ObjectMeta.Name
|
name := cfgmap.ObjectMeta.Name
|
||||||
if object, ok := mock.objects[name]; ok {
|
if object, ok := mock.objects[name]; ok {
|
||||||
return object, kberrs.NewAlreadyExists(api.Resource("tests"), name)
|
return object, kberrs.NewAlreadyExists(api.Resource("tests"), name)
|
||||||
}
|
}
|
||||||
mock.objects[name] = cfgmap
|
mock.objects[name] = cfgmap
|
||||||
return cfgmap, nil
|
return cfgmap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mock *MockConfigMapsInterface) Update(cfgmap *api.ConfigMap) (*api.ConfigMap, error) {
|
func (mock *MockConfigMapsInterface) Update(cfgmap *api.ConfigMap) (*api.ConfigMap, error) {
|
||||||
name := cfgmap.ObjectMeta.Name
|
name := cfgmap.ObjectMeta.Name
|
||||||
if _, ok := mock.objects[name]; !ok {
|
if _, ok := mock.objects[name]; !ok {
|
||||||
return nil, kberrs.NewNotFound(api.Resource("tests"), name)
|
return nil, kberrs.NewNotFound(api.Resource("tests"), name)
|
||||||
}
|
}
|
||||||
mock.objects[name] = cfgmap
|
mock.objects[name] = cfgmap
|
||||||
return cfgmap, nil
|
return cfgmap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mock *MockConfigMapsInterface) Delete(name string) error {
|
func (mock *MockConfigMapsInterface) Delete(name string) error {
|
||||||
if _, ok := mock.objects[name]; !ok {
|
if _, ok := mock.objects[name]; !ok {
|
||||||
return kberrs.NewNotFound(api.Resource("tests"), name)
|
return kberrs.NewNotFound(api.Resource("tests"), name)
|
||||||
}
|
}
|
||||||
delete(mock.objects, name)
|
delete(mock.objects, name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue