MCPcopy
hub / github.com/cli/cli / TestRun_Duration

Function TestRun_Duration

pkg/cmd/run/shared/shared_test.go:61–109  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func TestRun_Duration(t *testing.T) {
62 now, _ := time.Parse(time.RFC3339, "2022-07-20T11:22:58Z")
63
64 tests := []struct {
65 name string
66 json string
67 wants string
68 }{
69 {
70 name: "no run_started_at",
71 json: heredoc.Doc(`
72 {
73 "created_at": "2022-07-20T11:20:13Z",
74 "updated_at": "2022-07-20T11:21:16Z",
75 "status": "completed"
76 }`),
77 wants: "1m3s",
78 },
79 {
80 name: "with run_started_at",
81 json: heredoc.Doc(`
82 {
83 "created_at": "2022-07-20T11:20:13Z",
84 "run_started_at": "2022-07-20T11:20:55Z",
85 "updated_at": "2022-07-20T11:21:16Z",
86 "status": "completed"
87 }`),
88 wants: "21s",
89 },
90 {
91 name: "in_progress",
92 json: heredoc.Doc(`
93 {
94 "created_at": "2022-07-20T11:20:13Z",
95 "run_started_at": "2022-07-20T11:20:55Z",
96 "updated_at": "2022-07-20T11:21:16Z",
97 "status": "in_progress"
98 }`),
99 wants: "2m3s",
100 },
101 }
102 for _, tt := range tests {
103 t.Run(tt.name, func(t *testing.T) {
104 var r Run
105 assert.NoError(t, json.Unmarshal([]byte(tt.json), &r))
106 assert.Equal(t, tt.wants, r.Duration(now).String())
107 })
108 }
109}
110
111func TestRunExportData(t *testing.T) {
112 oldestStartedAt, _ := time.Parse(time.RFC3339, "2022-07-20T11:20:13Z")

Callers

nothing calls this directly

Calls 4

DurationMethod · 0.95
EqualMethod · 0.80
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected