From 8d0ae0934bc689cf03e0fd5e2e2eceae38557072 Mon Sep 17 00:00:00 2001 From: K K George Date: Tue, 3 Sep 2019 17:11:26 +0000 Subject: [PATCH] Fix create time bug and change yes/no to true/false Signed-off-by: K K George --- handler/volume/describe.go | 6 +----- handler/volume/volume_test/describe_test.go | 2 +- pkg/portworx/volumeCommon.go | 14 +++++--------- pkg/portworx/volumeCommon_test.go | 20 ++++++++++---------- pkg/tui/statsview.go | 4 ++-- pkg/util/utils.go | 6 ++++-- 6 files changed, 23 insertions(+), 29 deletions(-) diff --git a/handler/volume/describe.go b/handler/volume/describe.go index 1f5456b3..3a755a2c 100644 --- a/handler/volume/describe.go +++ b/handler/volume/describe.go @@ -34,10 +34,6 @@ import ( v1 "k8s.io/api/core/v1" ) -const ( - timeLayout = "Jan 3 15:04:05 UTC 2006" -) - var describeVolumeCmd *cobra.Command var _ = commander.RegisterCommandVar(func() { @@ -238,7 +234,7 @@ func (p *VolumeDescribeFormatter) addVolumeBasicInfo( t.AddLine("HA:", spec.GetHaLevel()) t.AddLine("IO Priority:", spec.GetCos()) t.AddLine("Creation Time:", - prototime.TimestampToTime(v.GetCtime()).Format(timeLayout)) + prototime.TimestampToTime(v.GetCtime()).Format(util.TimeFormat)) if v.GetSource() != nil && len(v.GetSource().GetParent()) != 0 { t.AddLine("Parent:", v.GetSource().GetParent()) } diff --git a/handler/volume/volume_test/describe_test.go b/handler/volume/volume_test/describe_test.go index ffb3a20e..24c24d7d 100644 --- a/handler/volume/volume_test/describe_test.go +++ b/handler/volume/volume_test/describe_test.go @@ -128,7 +128,7 @@ func verifyVolumeDescription( index++ } k, v = getKeyValue(d[index]) - verifyKeyValue(t, k, v, "Shared", "no") + verifyKeyValue(t, k, v, "Shared", "false") index++ k, v = getKeyValue(d[index]) verifyKeyValue(t, k, v, "Status", "UP") diff --git a/pkg/portworx/volumeCommon.go b/pkg/portworx/volumeCommon.go index a1a6d0f5..13dfe404 100644 --- a/pkg/portworx/volumeCommon.go +++ b/pkg/portworx/volumeCommon.go @@ -21,10 +21,6 @@ import ( "github.com/portworx/pxc/pkg/openstorage/sched" ) -const ( - timeLayout = "Jan 2 15:04:05 UTC 2006" -) - // SchedSummary returns the formatted string version of the schedule func SchedSummary(v *api.Volume) ([]string, error) { schedule := v.GetSpec().GetSnapshotSchedule() @@ -56,15 +52,15 @@ func SharedString(v *api.Volume) string { if v.Spec.Sharedv4 { return "v4" } - return YesOrNo(v.Spec.Shared) + return TrueOrFalse(v.Spec.Shared) } -// YesOrNo returns the string representation of bool -func YesOrNo(b bool) string { +// TrueOrFalse returns the string representation of bool +func TrueOrFalse(b bool) string { if b { - return "yes" + return "true" } else { - return "no" + return "false" } } diff --git a/pkg/portworx/volumeCommon_test.go b/pkg/portworx/volumeCommon_test.go index 21c4071e..48dd1a97 100644 --- a/pkg/portworx/volumeCommon_test.go +++ b/pkg/portworx/volumeCommon_test.go @@ -47,12 +47,12 @@ var ( "pvc-34d0f15c-65b9-4229-8b3e-b7bb912e382f": []string{}, } expectedShared = map[string]string{ - "tp1": "no", - "tp2": "no", - "tp2-snap": "no", - "tp3": "no", - "pvc-6fc1fe2d-25f4-40b0-a616-04c019572154": "no", - "pvc-34d0f15c-65b9-4229-8b3e-b7bb912e382f": "yes", + "tp1": "false", + "tp2": "false", + "tp2-snap": "false", + "tp3": "false", + "pvc-6fc1fe2d-25f4-40b0-a616-04c019572154": "false", + "pvc-34d0f15c-65b9-4229-8b3e-b7bb912e382f": "true", } ) @@ -70,10 +70,10 @@ func testVolumeCommon(t *testing.T, volOps PxVolumeOps, v *api.Volume) { ba := BooleanAttributes(v) eba := expectedAttributes[name] assert.Equalf(t, reflect.DeepEqual(ba, eba), true, "Wrong attributes for %s", name) - y := YesOrNo(true) - assert.Equal(t, y, "yes", "bool translation not correct") - n := YesOrNo(false) - assert.Equal(t, n, "no", "bool translation not correct") + y := TrueOrFalse(true) + assert.Equal(t, y, "true", "bool translation not correct") + n := TrueOrFalse(false) + assert.Equal(t, n, "false", "bool translation not correct") } func TestVolumeCommon(t *testing.T) { diff --git a/pkg/tui/statsview.go b/pkg/tui/statsview.go index 6e6472bf..5eb45d80 100644 --- a/pkg/tui/statsview.go +++ b/pkg/tui/statsview.go @@ -22,6 +22,7 @@ import ( ui "github.com/gizak/termui/v3" "github.com/gizak/termui/v3/widgets" + "github.com/portworx/pxc/pkg/util" ) type StatsModel interface { @@ -71,7 +72,6 @@ type statsView struct { const ( TOP_LINE_HEIGHT = 2 - TIME_FORMAT = "Jan 3 15:04:05 UTC 2006" TABLE_WIDTH_RATIO = 0.75 // Occupy 75% of terminal MAX_GRAPH_POINTS = 400 ) @@ -139,7 +139,7 @@ func (tv *statsView) Display(ti StatsModel, interval time.Duration) error { func getCurrentDateTime() string { now := time.Now() - return now.Format(TIME_FORMAT) + return now.Format(util.TimeFormat) } func (tv *statsView) toggleSortOrder(ti StatsModel) error { diff --git a/pkg/util/utils.go b/pkg/util/utils.go index ac623dc0..aca830b1 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -18,12 +18,13 @@ package util import ( "errors" "fmt" - "github.com/asaskevich/govalidator" - api "github.com/libopenstorage/openstorage-sdk-clients/sdk/golang" "net" "os" "strings" "time" + + "github.com/asaskevich/govalidator" + api "github.com/libopenstorage/openstorage-sdk-clients/sdk/golang" ) var ( @@ -32,6 +33,7 @@ var ( const ( DefaultPort = "9020" + TimeFormat = "Jan 2 15:04:05 UTC 2006" ) // ListContains returns true when string s is found in the list