Skip to content

Commit

Permalink
Merge pull request #66 from kkg-portworx/timebug
Browse files Browse the repository at this point in the history
Fix create time bug and change yes/no to true/false
  • Loading branch information
lpabon authored Sep 10, 2019
2 parents c2f6068 + 8d0ae09 commit 55d01b8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 29 deletions.
6 changes: 1 addition & 5 deletions handler/volume/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -239,7 +235,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())
}
Expand Down
2 changes: 1 addition & 1 deletion handler/volume/volume_test/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 5 additions & 9 deletions pkg/portworx/volumeCommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
}
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/portworx/volumeCommon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
)

Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/tui/statsview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down

0 comments on commit 55d01b8

Please sign in to comment.