mirror of https://github.com/helm/helm
This is an in-memory storage layer for storing releases. This will be superseded by the Kubernetes ConfigMap implementtion.pull/613/head
parent
a4a0c79fc4
commit
fa6a33c349
@ -0,0 +1,7 @@
|
||||
/*Package storage implements storage for Tiller objects.
|
||||
|
||||
Tiller stores releases (see 'cmd/tiller/environment'.Environment). The backend
|
||||
storage mechanism may be implemented with different backends. This package
|
||||
and its subpackages provide storage layers for Tiller objects.
|
||||
*/
|
||||
package storage
|
@ -0,0 +1,53 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/deis/tiller/pkg/hapi"
|
||||
)
|
||||
|
||||
// Memory is an in-memory ReleaseStorage implementation.
|
||||
type Memory struct {
|
||||
releases map[string]*hapi.Release
|
||||
}
|
||||
|
||||
func NewMemory() *Memory {
|
||||
return &Memory{
|
||||
releases: map[string]*hapi.Release{},
|
||||
}
|
||||
}
|
||||
|
||||
var ErrNotFound = errors.New("release not found")
|
||||
|
||||
// Get returns the named Release.
|
||||
//
|
||||
// If the release is not found, an ErrNotFound error is returned.
|
||||
func (m *Memory) Get(k string) (*hapi.Release, error) {
|
||||
v, ok := m.releases[k]
|
||||
if !ok {
|
||||
return v, ErrNotFound
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Set sets a release.
|
||||
//
|
||||
// TODO: Is there any reason why Set doesn't just use the release name?
|
||||
func (m *Memory) Set(k string, rel *hapi.Release) error {
|
||||
m.releases[k] = rel
|
||||
return nil
|
||||
}
|
||||
|
||||
// List returns all releases
|
||||
func (m *Memory) List() ([]*hapi.Release, error) {
|
||||
buf := make([]*hapi.Release, len(m.releases))
|
||||
i := 0
|
||||
for _, v := range m.releases {
|
||||
buf[i] = v
|
||||
i++
|
||||
}
|
||||
return buf, nil
|
||||
}
|
||||
func (m *Memory) Query(labels map[string]string) ([]*hapi.Release, error) {
|
||||
return []*hapi.Release{}, errors.New("Cannot implement until hapi.Release is defined.")
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/deis/tiller/pkg/hapi"
|
||||
)
|
||||
|
||||
func TestSet(t *testing.T) {
|
||||
k := "test-1"
|
||||
r := &hapi.Release{Name: k}
|
||||
|
||||
ms := NewMemory()
|
||||
if err := ms.Set(k, r); err != nil {
|
||||
t.Fatalf("Failed set: %s", err)
|
||||
}
|
||||
|
||||
if ms.releases[k].Name != k {
|
||||
t.Errorf("Unexpected release name: %s", ms.releases[k].Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
k := "test-1"
|
||||
r := &hapi.Release{Name: k}
|
||||
|
||||
ms := NewMemory()
|
||||
ms.Set(k, r)
|
||||
|
||||
if out, err := ms.Get(k); err != nil {
|
||||
t.Errorf("Could not get %s: %s", k, err)
|
||||
} else if out.Name != k {
|
||||
t.Errorf("Expected %s, got %s", k, out.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
ms := NewMemory()
|
||||
rels := []string{"a", "b", "c"}
|
||||
|
||||
for _, k := range rels {
|
||||
ms.Set(k, &hapi.Release{Name: k})
|
||||
}
|
||||
|
||||
l, err := ms.List()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(l) != 3 {
|
||||
t.Errorf("Expected 3, got %d", len(l))
|
||||
}
|
||||
|
||||
for _, n := range rels {
|
||||
foundN := false
|
||||
for _, rr := range l {
|
||||
if rr.Name == n {
|
||||
foundN = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !foundN {
|
||||
t.Errorf("Did not find %s in list.", n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuery(t *testing.T) {
|
||||
t.Skip("Not Implemented")
|
||||
}
|
Loading…
Reference in new issue