MCPcopy Index your code
hub / github.com/coder/coder / TestTemplateInsights_BadRequest

Function TestTemplateInsights_BadRequest

coderd/insights_test.go:2122–2161  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2120}
2121
2122func TestTemplateInsights_BadRequest(t *testing.T) {
2123 t.Parallel()
2124
2125 client := coderdtest.New(t, &coderdtest.Options{})
2126 _ = coderdtest.CreateFirstUser(t, client)
2127
2128 y, m, d := time.Now().UTC().Date()
2129 today := time.Date(y, m, d, 0, 0, 0, 0, time.UTC)
2130
2131 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
2132 defer cancel()
2133
2134 _, err := client.TemplateInsights(ctx, codersdk.TemplateInsightsRequest{
2135 StartTime: today,
2136 EndTime: today.AddDate(0, 0, -1),
2137 })
2138 assert.Error(t, err, "want error for end time before start time")
2139
2140 _, err = client.TemplateInsights(ctx, codersdk.TemplateInsightsRequest{
2141 StartTime: today.AddDate(0, 0, -1),
2142 EndTime: today,
2143 Interval: "invalid",
2144 })
2145 assert.Error(t, err, "want error for bad interval")
2146
2147 _, err = client.TemplateInsights(ctx, codersdk.TemplateInsightsRequest{
2148 StartTime: today.AddDate(0, 0, -5),
2149 EndTime: today,
2150 Interval: codersdk.InsightsReportIntervalWeek,
2151 })
2152 assert.Error(t, err, "last report interval must have at least 6 days")
2153
2154 _, err = client.TemplateInsights(ctx, codersdk.TemplateInsightsRequest{
2155 StartTime: today.AddDate(0, 0, -1),
2156 EndTime: today,
2157 Interval: codersdk.InsightsReportIntervalWeek,
2158 Sections: []codersdk.TemplateInsightsSection{"invalid"},
2159 })
2160 assert.Error(t, err, "want error for bad section")
2161}
2162
2163func TestTemplateInsights_RBAC(t *testing.T) {
2164 t.Parallel()

Callers

nothing calls this directly

Calls 4

NewFunction · 0.92
CreateFirstUserFunction · 0.92
TemplateInsightsMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected