Skip to content

Commit bffc673

Browse files
committed
unexport insights time layout
1 parent 87b1b90 commit bffc673

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

coderd/insights.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
"github.com/coder/coder/codersdk"
1717
)
1818

19+
// Duplicated in codersdk.
20+
const insightsTimeLayout = time.RFC3339
21+
1922
// @Summary Get deployment DAUs
2023
// @ID get-deployment-daus
2124
// @Security CoderSessionToken
@@ -324,14 +327,14 @@ func parseInsightsStartAndEndTime(ctx context.Context, rw http.ResponseWriter, s
324327
{"start_time", startTimeString, &startTime},
325328
{"end_time", endTimeString, &endTime},
326329
} {
327-
t, err := time.Parse(codersdk.InsightsTimeLayout, qp.value)
330+
t, err := time.Parse(insightsTimeLayout, qp.value)
328331
if err != nil {
329332
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
330333
Message: "Query parameter has invalid value.",
331334
Validations: []codersdk.ValidationError{
332335
{
333336
Field: qp.name,
334-
Detail: fmt.Sprintf("Query param %q must be a valid date format (%s): %s", qp.name, codersdk.InsightsTimeLayout, err.Error()),
337+
Detail: fmt.Sprintf("Query param %q must be a valid date format (%s): %s", qp.name, insightsTimeLayout, err.Error()),
335338
},
336339
},
337340
})

coderd/insights_internal_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import (
88

99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
11-
12-
"github.com/coder/coder/codersdk"
1311
)
1412

1513
func Test_parseInsightsStartAndEndTime(t *testing.T) {
1614
t.Parallel()
1715

18-
layout := codersdk.InsightsTimeLayout
16+
layout := insightsTimeLayout
1917
now := time.Now().UTC()
2018
y, m, d := now.Date()
2119
today := time.Date(y, m, d, 0, 0, 0, 0, time.UTC)
@@ -135,11 +133,11 @@ func Test_parseInsightsStartAndEndTime(t *testing.T) {
135133

136134
// assert.Equal is unable to test location equality, so we
137135
// use assert.WithinDuration.
136+
assert.Equal(t, tt.wantOk, gotOk)
138137
assert.WithinDuration(t, tt.wantStartTime, gotStartTime, 0)
139138
assert.True(t, tt.wantStartTime.Equal(gotStartTime))
140139
assert.WithinDuration(t, tt.wantEndTime, gotEndTime, 0)
141140
assert.True(t, tt.wantEndTime.Equal(gotEndTime))
142-
assert.Equal(t, tt.wantOk, gotOk)
143141
})
144142
}
145143
}

codersdk/insights.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import (
1212
"golang.org/x/xerrors"
1313
)
1414

15-
const InsightsTimeLayout = time.RFC3339
15+
// Duplicated in coderd.
16+
const insightsTimeLayout = time.RFC3339
1617

1718
// InsightsReportInterval is the interval of time over which to generate a
1819
// smaller insights report within a time range.
@@ -61,8 +62,8 @@ type UserLatencyInsightsRequest struct {
6162

6263
func (c *Client) UserLatencyInsights(ctx context.Context, req UserLatencyInsightsRequest) (UserLatencyInsightsResponse, error) {
6364
var qp []string
64-
qp = append(qp, fmt.Sprintf("start_time=%s", req.StartTime.Format(InsightsTimeLayout)))
65-
qp = append(qp, fmt.Sprintf("end_time=%s", req.EndTime.Format(InsightsTimeLayout)))
65+
qp = append(qp, fmt.Sprintf("start_time=%s", req.StartTime.Format(insightsTimeLayout)))
66+
qp = append(qp, fmt.Sprintf("end_time=%s", req.EndTime.Format(insightsTimeLayout)))
6667
if len(req.TemplateIDs) > 0 {
6768
var templateIDs []string
6869
for _, id := range req.TemplateIDs {
@@ -161,8 +162,8 @@ type TemplateInsightsRequest struct {
161162

162163
func (c *Client) TemplateInsights(ctx context.Context, req TemplateInsightsRequest) (TemplateInsightsResponse, error) {
163164
var qp []string
164-
qp = append(qp, fmt.Sprintf("start_time=%s", req.StartTime.Format(InsightsTimeLayout)))
165-
qp = append(qp, fmt.Sprintf("end_time=%s", req.EndTime.Format(InsightsTimeLayout)))
165+
qp = append(qp, fmt.Sprintf("start_time=%s", req.StartTime.Format(insightsTimeLayout)))
166+
qp = append(qp, fmt.Sprintf("end_time=%s", req.EndTime.Format(insightsTimeLayout)))
166167
if len(req.TemplateIDs) > 0 {
167168
var templateIDs []string
168169
for _, id := range req.TemplateIDs {

0 commit comments

Comments
 (0)