Skip to content

Commit bc31e21

Browse files
committed
chore(workflow-cli): unified time format
1 parent 89d9430 commit bc31e21

11 files changed

Lines changed: 33 additions & 39 deletions

File tree

cmd/apps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (d *DryccCmd) AppInfo(appID string) error {
133133
table.Append([]string{"", "Release:", process.Release})
134134
table.Append([]string{"", "State:", process.State})
135135
table.Append([]string{"", "Type:", process.Type})
136-
table.Append([]string{"", "Started:", process.Started.Format("2006-01-02T15:04:05MST")})
136+
table.Append([]string{"", "Started:", d.formatTime(process.Started)})
137137
if len(processes) > index+1 {
138138
table.Append([]string{""})
139139
}

cmd/apps_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Processes:
198198
Release: v2
199199
State: up
200200
Type: cmd
201-
Started: 2016-08-22T17:42:16UTC
201+
Started: 2016-08-22T17:42:16Z
202202
Domains:
203203
Domain: lorem-ipsum
204204
Created: 2016-08-22T17:40:16Z

cmd/certs.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66
"strings"
7-
"time"
87

98
drycc "github.com/drycc/controller-sdk-go"
109
"github.com/drycc/controller-sdk-go/certs"
@@ -136,8 +135,8 @@ func (d *DryccCmd) CertInfo(name string) error {
136135
table.Append([]string{""})
137136
table.Append([]string{"Connected Domains:", safeGetString(strings.Join(cert.Domains[:], ","))})
138137
table.Append([]string{"Owner:", safeGetString(cert.Owner)})
139-
table.Append([]string{"Created:", d.formatTime(safeGetTime(cert.Created, time.RFC3339))})
140-
table.Append([]string{"Updated:", d.formatTime(safeGetTime(cert.Updated, time.RFC3339))})
138+
table.Append([]string{"Created:", d.formatTime(cert.Created)})
139+
table.Append([]string{"Updated:", d.formatTime(cert.Updated)})
141140
table.Render()
142141
return nil
143142
}

cmd/certs_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ func TestCertsInfo(t *testing.T) {
168168
"issuer": "testca",
169169
"subject": "testing",
170170
"common_name": "test.drycc.com",
171-
"created": "2016-06-09T00:00:00UTC",
172-
"updated": "2016-06-09T00:00:00UTC",
171+
"created": "2016-06-09T00:00:00Z",
172+
"updated": "2016-06-09T00:00:00Z",
173173
"expires": "2016-06-09T00:00:00UTC",
174174
"starts": "2016-06-09T00:00:00UTC",
175175
"fingerprint": "ab:12:ab:12:ab",
@@ -222,8 +222,8 @@ Subject: <none>
222222
223223
Connected Domains: <none>
224224
Owner: <none>
225-
Created: <none>
226-
Updated: <none>
225+
Created:
226+
Updated:
227227
`, "output")
228228
}
229229

cmd/ps.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,23 @@ func (d *DryccCmd) PsDescribe(appID, podID string) error {
132132
table.Append([]string{"State:", key})
133133
value := containerState.State[key]
134134
for innerKey := range value {
135-
table.Append([]string{fmt.Sprintf(" %s:", innerKey), strconv.Quote(fmt.Sprintf("%v", value[innerKey]))})
135+
innerValue := strconv.Quote(fmt.Sprintf("%v", value[innerKey]))
136+
if innerKey == "startedAt" || innerKey == "finishedAt" {
137+
innerValue = d.formatTime(fmt.Sprintf("%s", value[innerKey]))
138+
}
139+
table.Append([]string{fmt.Sprintf(" %s:", innerKey), innerValue})
136140
}
137141
}
138142
// LastState
139143
for key := range containerState.LastState {
140144
table.Append([]string{"Last State:", key})
141145
value := containerState.LastState[key]
142146
for innerKey := range value {
143-
table.Append([]string{fmt.Sprintf(" %s:", innerKey), strconv.Quote(fmt.Sprintf("%v", value[innerKey]))})
147+
innerValue := strconv.Quote(fmt.Sprintf("%v", value[innerKey]))
148+
if innerKey == "startedAt" || innerKey == "finishedAt" {
149+
innerValue = d.formatTime(fmt.Sprintf("%s", value[innerKey]))
150+
}
151+
table.Append([]string{fmt.Sprintf(" %s:", innerKey), innerValue})
144152
}
145153
}
146154
table.Append([]string{"Ready:", fmt.Sprintf("%v", containerState.Ready)})
@@ -162,7 +170,7 @@ func (d *DryccCmd) PsDescribe(appID, podID string) error {
162170
te.Append([]string{
163171
fmt.Sprintf(" %s", ev.Reason),
164172
ev.Message,
165-
ev.Created.Format("2006-01-02T15:04:05MST"),
173+
d.formatTime(ev.Created),
166174
})
167175
}
168176
te.Render()
@@ -208,7 +216,7 @@ func printProcesses(d *DryccCmd, appID string, input []api.Pods) {
208216
pod.Type,
209217
pod.Ready,
210218
fmt.Sprintf("%v", pod.Restarts),
211-
pod.Started.Format("2006-01-02T15:04:05MST"),
219+
d.formatTime(pod.Started),
212220
})
213221
}
214222
}

cmd/ps_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@ import (
66
"io"
77
"net/http"
88
"testing"
9-
"time"
109

1110
"github.com/drycc/controller-sdk-go/api"
12-
dtime "github.com/drycc/controller-sdk-go/pkg/time"
1311
"github.com/drycc/workflow-cli/pkg/testutil"
1412
"github.com/stretchr/testify/assert"
1513
"golang.org/x/net/websocket"
1614
)
1715

1816
func TestPrintProcesses(t *testing.T) {
1917
var b bytes.Buffer
20-
d, err := time.Parse("2006-01-02T15:04:05MST", "2023-11-15T11:55:16CST")
21-
if err != nil {
22-
t.Fatal(err)
23-
}
2418
pods := []api.Pods{
2519
{
2620
Release: "v3",
@@ -29,7 +23,7 @@ func TestPrintProcesses(t *testing.T) {
2923
State: "up",
3024
Ready: "1/1",
3125
Restarts: 0,
32-
Started: dtime.Time{Time: &d},
26+
Started: "2023-11-15T11:55:16CST",
3327
},
3428
{
3529
Release: "v3",
@@ -38,7 +32,7 @@ func TestPrintProcesses(t *testing.T) {
3832
State: "up",
3933
Ready: "1/1",
4034
Restarts: 0,
41-
Started: dtime.Time{Time: &d},
35+
Started: "2023-11-15T11:55:16CST",
4236
},
4337
}
4438
cf, server, err := testutil.NewTestServerAndClient()
@@ -88,8 +82,8 @@ func TestPsList(t *testing.T) {
8882
err = cmdr.PsList("foo", -1)
8983
assert.NoError(t, err)
9084

91-
assert.Equal(t, b.String(), `NAME RELEASE STATE PTYPE READY RESTARTS STARTED
92-
foo-web-4084101150-c871y v2 up web 1/1 0 2016-02-13T00:47:52UTC
85+
assert.Equal(t, b.String(), `NAME RELEASE STATE PTYPE READY RESTARTS STARTED
86+
foo-web-4084101150-c871y v2 up web 1/1 0 2016-02-13T00:47:52
9387
`, "output")
9488
}
9589

cmd/pts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func printProcessTypes(d *DryccCmd, appID string, ptypes api.Ptypes) {
130130
pt.Ready,
131131
fmt.Sprintf("%v", pt.UpToDate),
132132
fmt.Sprintf("%v", pt.AvailableReplicas),
133-
pt.Started.Format("2006-01-02T15:04:05MST"),
133+
d.formatTime(pt.Started),
134134
})
135135
}
136136
table.Render()
@@ -190,7 +190,7 @@ func printProcessTypeDetail(d *DryccCmd, ptypeStates api.PtypeStates, events api
190190
te.Append([]string{
191191
fmt.Sprintf(" %s", ev.Reason),
192192
ev.Message,
193-
ev.Created.Format("2006-01-02T15:04:05MST"),
193+
d.formatTime(ev.Created),
194194
})
195195
}
196196
te.Render()

cmd/pts_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,30 @@ import (
55
"fmt"
66
"net/http"
77
"testing"
8-
"time"
98

109
"github.com/drycc/controller-sdk-go/api"
11-
dtime "github.com/drycc/controller-sdk-go/pkg/time"
1210
"github.com/drycc/workflow-cli/pkg/testutil"
1311
"github.com/stretchr/testify/assert"
1412
)
1513

1614
func TestPrintProcessTypes(t *testing.T) {
1715
var b bytes.Buffer
18-
d, err := time.Parse("2006-01-02T15:04:05MST", "2024-07-04T14:33:00CST")
19-
if err != nil {
20-
t.Fatal(err)
21-
}
2216
ptypes := api.Ptypes{
2317
{
2418
Name: "web",
2519
Release: "v1",
2620
Ready: "1/1",
2721
UpToDate: 1,
2822
AvailableReplicas: 1,
29-
Started: dtime.Time{Time: &d},
23+
Started: "2024-07-04T14:33:00CST",
3024
},
3125
{
3226
Name: "worker",
3327
Release: "v1",
3428
Ready: "1/1",
3529
UpToDate: 1,
3630
AvailableReplicas: 1,
37-
Started: dtime.Time{Time: &d},
31+
Started: "2024-07-04T14:33:00CST",
3832
},
3933
}
4034
cf, server, err := testutil.NewTestServerAndClient()
@@ -83,8 +77,8 @@ func TestPtsList(t *testing.T) {
8377
err = cmdr.PtsList("foo", -1)
8478
assert.NoError(t, err)
8579

86-
assert.Equal(t, b.String(), `NAME RELEASE READY UP-TO-DATE AVAILABLE STARTED
87-
web v1 1/1 1 1 2016-02-13T00:47:52UTC
80+
assert.Equal(t, b.String(), `NAME RELEASE READY UP-TO-DATE AVAILABLE STARTED
81+
web v1 1/1 1 1 2016-02-13T00:47:52
8882
`, "output")
8983
}
9084

cmd/volumes.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func (d *DryccCmd) VolumesList(appID string, results int) error {
2727
if results == defaultLimit {
2828
results = s.Limit
2929
}
30-
//fmt.Println("-----app-----", appID) # debug
3130
volumes, count, err := volumes.List(s.Client, appID, results)
3231
if d.checkAPICompatibility(s.Client, err) != nil {
3332
return err

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22
55
require (
66
github.com/containerd/console v1.0.4
77
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
8-
github.com/drycc/controller-sdk-go v0.0.0-20240709083211-c3849cd23514
8+
github.com/drycc/controller-sdk-go v0.0.0-20240710072101-82db20de8e4a
99
github.com/drycc/pkg v0.0.0-20240225112316-78fc9239f51f
1010
github.com/olekukonko/tablewriter v0.0.5
1111
github.com/stretchr/testify v1.9.0

0 commit comments

Comments
 (0)