Skip to content

Commit 033fd4e

Browse files
committed
fix unit tests
1 parent bc3088f commit 033fd4e

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

coderd/metricscache/metricscache.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import (
2222
"github.com/coder/retry"
2323
)
2424

25+
func OnlyDate(t time.Time) string {
26+
return t.Format("2006-01-02")
27+
}
28+
2529
// deploymentTimezoneOffsets are the timezones that are cached and supported.
2630
// Any non-listed timezone offsets will need to use the closest supported one.
2731
var deploymentTimezoneOffsets = []int{
@@ -168,7 +172,7 @@ func convertDAUResponse[T dauRow](rows []T, tzOffset int) codersdk.DAUsResponse
168172
resp.Entries = append(resp.Entries, codersdk.DAUEntry{
169173
// This date is truncated to 00:00:00 of the given day, so only
170174
// return date information.
171-
Date: date.Format("2006-01-02"),
175+
Date: OnlyDate(date),
172176
Amount: len(respMap[date]),
173177
})
174178
}

coderd/metricscache/metricscache_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ func TestCache_TemplateUsers(t *testing.T) {
6767
},
6868
tplWant: want{[]codersdk.DAUEntry{
6969
{
70-
Date: date(2022, 8, 27),
70+
Date: metricscache.OnlyDate(date(2022, 8, 27)),
7171
Amount: 1,
7272
},
7373
{
74-
Date: date(2022, 8, 28),
74+
Date: metricscache.OnlyDate(date(2022, 8, 28)),
7575
Amount: 0,
7676
},
7777
{
78-
Date: date(2022, 8, 29),
78+
Date: metricscache.OnlyDate(date(2022, 8, 29)),
7979
Amount: 0,
8080
},
8181
{
82-
Date: date(2022, 8, 30),
82+
Date: metricscache.OnlyDate(date(2022, 8, 30)),
8383
Amount: 1,
8484
},
8585
}, 1},
@@ -95,15 +95,15 @@ func TestCache_TemplateUsers(t *testing.T) {
9595
},
9696
tplWant: want{[]codersdk.DAUEntry{
9797
{
98-
Date: date(2022, 8, 27),
98+
Date: metricscache.OnlyDate(date(2022, 8, 27)),
9999
Amount: 1,
100100
},
101101
{
102-
Date: date(2022, 8, 28),
102+
Date: metricscache.OnlyDate(date(2022, 8, 28)),
103103
Amount: 1,
104104
},
105105
{
106-
Date: date(2022, 8, 29),
106+
Date: metricscache.OnlyDate(date(2022, 8, 29)),
107107
Amount: 1,
108108
},
109109
}, 1},
@@ -121,31 +121,31 @@ func TestCache_TemplateUsers(t *testing.T) {
121121
},
122122
tplWant: want{[]codersdk.DAUEntry{
123123
{
124-
Date: date(2022, 1, 1),
124+
Date: metricscache.OnlyDate(date(2022, 1, 1)),
125125
Amount: 2,
126126
},
127127
{
128-
Date: date(2022, 1, 2),
128+
Date: metricscache.OnlyDate(date(2022, 1, 2)),
129129
Amount: 0,
130130
},
131131
{
132-
Date: date(2022, 1, 3),
132+
Date: metricscache.OnlyDate(date(2022, 1, 3)),
133133
Amount: 0,
134134
},
135135
{
136-
Date: date(2022, 1, 4),
136+
Date: metricscache.OnlyDate(date(2022, 1, 4)),
137137
Amount: 1,
138138
},
139139
{
140-
Date: date(2022, 1, 5),
140+
Date: metricscache.OnlyDate(date(2022, 1, 5)),
141141
Amount: 0,
142142
},
143143
{
144-
Date: date(2022, 1, 6),
144+
Date: metricscache.OnlyDate(date(2022, 1, 6)),
145145
Amount: 0,
146146
},
147147
{
148-
Date: date(2022, 1, 7),
148+
Date: metricscache.OnlyDate(date(2022, 1, 7)),
149149
Amount: 2,
150150
},
151151
}, 2},
@@ -164,17 +164,17 @@ func TestCache_TemplateUsers(t *testing.T) {
164164
},
165165
tplWant: want{[]codersdk.DAUEntry{
166166
{
167-
Date: date(2022, 1, 2),
167+
Date: metricscache.OnlyDate(date(2022, 1, 2)),
168168
Amount: 2,
169169
},
170170
}, 2},
171171
dauWant: []codersdk.DAUEntry{
172172
{
173-
Date: date(2022, 1, 1),
173+
Date: metricscache.OnlyDate(date(2022, 1, 1)),
174174
Amount: 2,
175175
},
176176
{
177-
Date: date(2022, 1, 2),
177+
Date: metricscache.OnlyDate(date(2022, 1, 2)),
178178
Amount: 2,
179179
},
180180
},
@@ -192,13 +192,13 @@ func TestCache_TemplateUsers(t *testing.T) {
192192
},
193193
dauWant: []codersdk.DAUEntry{
194194
{
195-
Date: date(2022, 1, 1),
195+
Date: metricscache.OnlyDate(date(2022, 1, 1)),
196196
Amount: 2,
197197
},
198198
},
199199
tplWant: want{[]codersdk.DAUEntry{
200200
{
201-
Date: date(2022, 1, 2),
201+
Date: metricscache.OnlyDate(date(2022, 1, 2)),
202202
Amount: 2,
203203
},
204204
}, 2},

0 commit comments

Comments
 (0)