more style fixes and cleanup

pull/1007/head
fibonacci1729 9 years ago
parent 559e9081fb
commit 94a154b745

@ -111,8 +111,7 @@ func (cfgmaps *ConfigMaps) Create(rls *rspb.Release) error {
var lbs labels
lbs.init()
lbs.set("STATE", "CREATED")
lbs.set("CREATED_AT", time.Now().String())
lbs.set("CREATED_AT", strconv.Itoa(int(time.Now().Unix())))
// create a new configmap to hold the release
obj, err := newConfigMapsObject(rls, lbs)
@ -139,8 +138,7 @@ func (cfgmaps *ConfigMaps) Update(rls *rspb.Release) error {
var lbs labels
lbs.init()
lbs.set("STATE", "UPDATED")
lbs.set("MODIFIED_AT", time.Now().String())
lbs.set("MODIFIED_AT", strconv.Itoa(int(time.Now().Unix())))
// create a new configmap object to hold the release
obj, err := newConfigMapsObject(rls, lbs)
@ -159,13 +157,6 @@ func (cfgmaps *ConfigMaps) Update(rls *rspb.Release) error {
// Delete deletes the ConfigMap holding the release named by key.
func (cfgmaps *ConfigMaps) Delete(key string) (rls *rspb.Release, err error) {
// set labels for configmaps object meta data
var lbs labels
lbs.init()
lbs.set("STATE", "DELETED")
lbs.set("MODIFIED_AT", time.Now().String())
// fetch the release to check existence
if rls, err = cfgmaps.Get(key); err != nil {
if kberrs.IsNotFound(err) {
@ -210,6 +201,7 @@ func newConfigMapsObject(rls *rspb.Release, lbs labels) (*api.ConfigMap, error)
// apply labels
lbs.set("NAME", rls.Name)
lbs.set("OWNER", owner)
lbs.set("STATUS", rspb.Status_Code_name[int32(rls.Info.Status.Code)])
lbs.set("VERSION", strconv.Itoa(int(rls.Version)))
// create and return configmap object

@ -28,7 +28,7 @@ import (
func TestConfigMapGet(t *testing.T) {
// test release
key := "key-1"
rls := &rspb.Release{Name: key, Version: 1}
rls := newTestRelease(key, 1, rspb.Status_DEPLOYED)
// create test fixture
cfgmaps := newTestFixture(t, rls)
@ -52,7 +52,7 @@ func TestConfigMapList(t *testing.T) {
func TestConfigMapCreate(t *testing.T) {
// setup
key := "key-1"
rls := &rspb.Release{Name: "key-1", Version: 1}
rls := newTestRelease(key, 1, rspb.Status_DEPLOYED)
// create test fixture
cfgmaps := newTestFixture(t, rls)
@ -62,10 +62,6 @@ func TestConfigMapCreate(t *testing.T) {
t.Fatalf("failed to create release with key %q: %s", key, err)
}
if err := cfgmaps.Create(rls); err != nil {
t.Fatalf("failed to create release with key %q: %s", key, err)
}
// get the release back
got, err := cfgmaps.Get(key)
if err != nil {
@ -81,7 +77,7 @@ func TestConfigMapCreate(t *testing.T) {
func TestConfigMapDelete(t *testing.T) {
// setup
key := "key-1"
rls := &rspb.Release{Name: "key-1", Version: 1}
rls := newTestRelease(key, 1, rspb.Status_DELETED)
// create test fixture
cfgmaps := newTestFixture(t, rls)
@ -101,7 +97,7 @@ func TestConfigMapDelete(t *testing.T) {
func TestConfigMapUpdate(t *testing.T) {
// setup
key := "key-1"
rls := &rspb.Release{Name: "key-1", Version: 1}
rls := newTestRelease(key, 1, rspb.Status_SUPERSEDED)
// create test fixture
cfgmaps := newTestFixture(t, rls)
@ -144,3 +140,8 @@ func newTestFixture(t *testing.T, list ...*rspb.Release) *ConfigMaps {
Fake: testclient.NewSimpleFake(objs...),
})
}
// newTestRelease creates a release object for testing
func newTestRelease(key string, version int32, status rspb.Status_Code) *rspb.Release {
return &rspb.Release{Name: key, Info: &rspb.Info{Status: &rspb.Status{Code: status}}, Version: version}
}

Loading…
Cancel
Save