forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dora_metrics_test.go
118 lines (104 loc) · 3.19 KB
/
dora_metrics_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package gitlab
import (
"fmt"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestDORAMetrics_GetProjectDORAMetrics(t *testing.T) {
mux, client := setup(t)
mux.HandleFunc("/api/v4/projects/1/dora/metrics", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
query := r.URL.Query()
for k, v := range map[string]string{
"metric": "deployment_frequency",
"start_date": "2021-03-01",
"end_date": "2021-03-08",
} {
if query.Get(k) != v {
t.Errorf("Query parameter %s: %s, want %s", k, query.Get(k), v)
}
}
fmt.Fprint(w, `
[
{ "date": "2021-03-01", "value": 3 },
{ "date": "2021-03-02", "value": 6 },
{ "date": "2021-03-03", "value": 0 },
{ "date": "2021-03-04", "value": 0 },
{ "date": "2021-03-05", "value": 0 },
{ "date": "2021-03-06", "value": 0 },
{ "date": "2021-03-07", "value": 0 },
{ "date": "2021-03-08", "value": 4 }
]
`)
})
want := []DORAMetric{
{Date: "2021-03-01", Value: 3},
{Date: "2021-03-02", Value: 6},
{Date: "2021-03-03", Value: 0},
{Date: "2021-03-04", Value: 0},
{Date: "2021-03-05", Value: 0},
{Date: "2021-03-06", Value: 0},
{Date: "2021-03-07", Value: 0},
{Date: "2021-03-08", Value: 4},
}
startDate := ISOTime(time.Date(2021, time.March, 1, 0, 0, 0, 0, time.UTC))
endDate := ISOTime(time.Date(2021, time.March, 8, 0, 0, 0, 0, time.UTC))
d, resp, err := client.DORAMetrics.GetProjectDORAMetrics(1, GetDORAMetricsOptions{
Metric: Ptr(DORAMetricDeploymentFrequency),
StartDate: &startDate,
EndDate: &endDate,
})
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, want, d)
}
func TestDORAMetrics_GetGroupDORAMetrics(t *testing.T) {
mux, client := setup(t)
mux.HandleFunc("/api/v4/groups/1/dora/metrics", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
query := r.URL.Query()
for k, v := range map[string]string{
"metric": "deployment_frequency",
"start_date": "2021-03-01",
"end_date": "2021-03-08",
} {
if query.Get(k) != v {
t.Errorf("Query parameter %s: %s, want %s", k, query.Get(k), v)
}
}
fmt.Fprint(w, `
[
{ "date": "2021-03-01", "value": 3 },
{ "date": "2021-03-02", "value": 6 },
{ "date": "2021-03-03", "value": 0 },
{ "date": "2021-03-04", "value": 0 },
{ "date": "2021-03-05", "value": 0 },
{ "date": "2021-03-06", "value": 0 },
{ "date": "2021-03-07", "value": 0 },
{ "date": "2021-03-08", "value": 4 }
]
`)
})
want := []DORAMetric{
{Date: "2021-03-01", Value: 3},
{Date: "2021-03-02", Value: 6},
{Date: "2021-03-03", Value: 0},
{Date: "2021-03-04", Value: 0},
{Date: "2021-03-05", Value: 0},
{Date: "2021-03-06", Value: 0},
{Date: "2021-03-07", Value: 0},
{Date: "2021-03-08", Value: 4},
}
startDate := ISOTime(time.Date(2021, time.March, 1, 0, 0, 0, 0, time.UTC))
endDate := ISOTime(time.Date(2021, time.March, 8, 0, 0, 0, 0, time.UTC))
d, resp, err := client.DORAMetrics.GetGroupDORAMetrics(1, GetDORAMetricsOptions{
Metric: Ptr(DORAMetricDeploymentFrequency),
StartDate: &startDate,
EndDate: &endDate,
})
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, want, d)
}