Skip to content

Commit 55d01b8

Browse files
authored
Merge pull request #66 from kkg-portworx/timebug
Fix create time bug and change yes/no to true/false
2 parents c2f6068 + 8d0ae09 commit 55d01b8

File tree

6 files changed

+23
-29
lines changed

6 files changed

+23
-29
lines changed

handler/volume/describe.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ import (
3434
v1 "k8s.io/api/core/v1"
3535
)
3636

37-
const (
38-
timeLayout = "Jan 3 15:04:05 UTC 2006"
39-
)
40-
4137
var describeVolumeCmd *cobra.Command
4238

4339
var _ = commander.RegisterCommandVar(func() {
@@ -239,7 +235,7 @@ func (p *VolumeDescribeFormatter) addVolumeBasicInfo(
239235
t.AddLine("HA:", spec.GetHaLevel())
240236
t.AddLine("IO Priority:", spec.GetCos())
241237
t.AddLine("Creation Time:",
242-
prototime.TimestampToTime(v.GetCtime()).Format(timeLayout))
238+
prototime.TimestampToTime(v.GetCtime()).Format(util.TimeFormat))
243239
if v.GetSource() != nil && len(v.GetSource().GetParent()) != 0 {
244240
t.AddLine("Parent:", v.GetSource().GetParent())
245241
}

handler/volume/volume_test/describe_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func verifyVolumeDescription(
128128
index++
129129
}
130130
k, v = getKeyValue(d[index])
131-
verifyKeyValue(t, k, v, "Shared", "no")
131+
verifyKeyValue(t, k, v, "Shared", "false")
132132
index++
133133
k, v = getKeyValue(d[index])
134134
verifyKeyValue(t, k, v, "Status", "UP")

pkg/portworx/volumeCommon.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ import (
2121
"github.com/portworx/pxc/pkg/openstorage/sched"
2222
)
2323

24-
const (
25-
timeLayout = "Jan 2 15:04:05 UTC 2006"
26-
)
27-
2824
// SchedSummary returns the formatted string version of the schedule
2925
func SchedSummary(v *api.Volume) ([]string, error) {
3026
schedule := v.GetSpec().GetSnapshotSchedule()
@@ -56,15 +52,15 @@ func SharedString(v *api.Volume) string {
5652
if v.Spec.Sharedv4 {
5753
return "v4"
5854
}
59-
return YesOrNo(v.Spec.Shared)
55+
return TrueOrFalse(v.Spec.Shared)
6056
}
6157

62-
// YesOrNo returns the string representation of bool
63-
func YesOrNo(b bool) string {
58+
// TrueOrFalse returns the string representation of bool
59+
func TrueOrFalse(b bool) string {
6460
if b {
65-
return "yes"
61+
return "true"
6662
} else {
67-
return "no"
63+
return "false"
6864
}
6965
}
7066

pkg/portworx/volumeCommon_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ var (
4747
"pvc-34d0f15c-65b9-4229-8b3e-b7bb912e382f": []string{},
4848
}
4949
expectedShared = map[string]string{
50-
"tp1": "no",
51-
"tp2": "no",
52-
"tp2-snap": "no",
53-
"tp3": "no",
54-
"pvc-6fc1fe2d-25f4-40b0-a616-04c019572154": "no",
55-
"pvc-34d0f15c-65b9-4229-8b3e-b7bb912e382f": "yes",
50+
"tp1": "false",
51+
"tp2": "false",
52+
"tp2-snap": "false",
53+
"tp3": "false",
54+
"pvc-6fc1fe2d-25f4-40b0-a616-04c019572154": "false",
55+
"pvc-34d0f15c-65b9-4229-8b3e-b7bb912e382f": "true",
5656
}
5757
)
5858

@@ -70,10 +70,10 @@ func testVolumeCommon(t *testing.T, volOps PxVolumeOps, v *api.Volume) {
7070
ba := BooleanAttributes(v)
7171
eba := expectedAttributes[name]
7272
assert.Equalf(t, reflect.DeepEqual(ba, eba), true, "Wrong attributes for %s", name)
73-
y := YesOrNo(true)
74-
assert.Equal(t, y, "yes", "bool translation not correct")
75-
n := YesOrNo(false)
76-
assert.Equal(t, n, "no", "bool translation not correct")
73+
y := TrueOrFalse(true)
74+
assert.Equal(t, y, "true", "bool translation not correct")
75+
n := TrueOrFalse(false)
76+
assert.Equal(t, n, "false", "bool translation not correct")
7777
}
7878

7979
func TestVolumeCommon(t *testing.T) {

pkg/tui/statsview.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
ui "github.com/gizak/termui/v3"
2424
"github.com/gizak/termui/v3/widgets"
25+
"github.com/portworx/pxc/pkg/util"
2526
)
2627

2728
type StatsModel interface {
@@ -71,7 +72,6 @@ type statsView struct {
7172

7273
const (
7374
TOP_LINE_HEIGHT = 2
74-
TIME_FORMAT = "Jan 3 15:04:05 UTC 2006"
7575
TABLE_WIDTH_RATIO = 0.75 // Occupy 75% of terminal
7676
MAX_GRAPH_POINTS = 400
7777
)
@@ -139,7 +139,7 @@ func (tv *statsView) Display(ti StatsModel, interval time.Duration) error {
139139

140140
func getCurrentDateTime() string {
141141
now := time.Now()
142-
return now.Format(TIME_FORMAT)
142+
return now.Format(util.TimeFormat)
143143
}
144144

145145
func (tv *statsView) toggleSortOrder(ti StatsModel) error {

pkg/util/utils.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ package util
1818
import (
1919
"errors"
2020
"fmt"
21-
"github.com/asaskevich/govalidator"
22-
api "github.com/libopenstorage/openstorage-sdk-clients/sdk/golang"
2321
"net"
2422
"os"
2523
"strings"
2624
"time"
25+
26+
"github.com/asaskevich/govalidator"
27+
api "github.com/libopenstorage/openstorage-sdk-clients/sdk/golang"
2728
)
2829

2930
var (
@@ -32,6 +33,7 @@ var (
3233

3334
const (
3435
DefaultPort = "9020"
36+
TimeFormat = "Jan 2 15:04:05 UTC 2006"
3537
)
3638

3739
// ListContains returns true when string s is found in the list

0 commit comments

Comments
 (0)