forked from OpsLevel/opslevel-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscorecards_test.go
More file actions
166 lines (146 loc) · 6.1 KB
/
scorecards_test.go
File metadata and controls
166 lines (146 loc) · 6.1 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package opslevel_test
import (
"testing"
ol "github.com/opslevel/opslevel-go/v2023"
"github.com/rocktavious/autopilot/v2023"
)
var (
scorecardId = "Z2lkOi8vMTIzNDU2Nzg5MTAK" // 12345678910
fakeOwnerId = ol.NewID("Z2lkOi8vMTIzNDU2Nzg5Cg==") // 123456789
newOwnerId = ol.NewID("Z2lkOi8vMTIzNDU2Nzc3Cg==") // 123456777
fakeFilterId = ol.NewID("Z2lkOi8vMTIzNDU2MTIzCg==") // 123456123
newFilterId = ol.NewID("Z2lkOi8vMTIzNDU2NDU2Cg==") // 123456456
)
func TestCreateScorecard(t *testing.T) {
testRequest := NewTestRequest(
`{{ template "scorecard_create_request" }}`,
`{{ template "scorecard_create_request_vars" }}`,
`{{ template "scorecard_create_response" }}`,
)
name := "new scorecard"
description := "a new scorecard with an attached filter id"
client := BestTestClient(t, "scorecards/create_scorecard", testRequest)
sc, err := client.CreateScorecard(ol.ScorecardInput{
Name: name,
Description: &description,
OwnerId: *fakeOwnerId,
FilterId: fakeFilterId,
AffectsOverallServiceLevels: ol.Bool(true),
})
autopilot.Ok(t, err)
autopilot.Equals(t, name, sc.Name)
autopilot.Equals(t, description, sc.Description)
autopilot.Equals(t, *fakeOwnerId, sc.Owner.Id())
autopilot.Equals(t, *fakeFilterId, sc.Filter.Id)
autopilot.Equals(t, true, sc.AffectsOverallServiceLevels)
}
func TestCreateScorecardDoesNotAffectServiceLevels(t *testing.T) {
testRequest := NewTestRequest(
`{{ template "scorecard_create_request" }}`,
`{{ template "scorecard_create_request_vars_affects_service_levels_false" }}`,
`{{ template "scorecard_create_response_affects_service_levels_false" }}`,
)
name := "new scorecard"
description := "a new scorecard with an attached filter id"
client := BestTestClient(t, "scorecards/create_scorecard_not_affects_service_levels", testRequest)
sc, err := client.CreateScorecard(ol.ScorecardInput{
Name: name,
Description: &description,
OwnerId: *fakeOwnerId,
FilterId: fakeFilterId,
AffectsOverallServiceLevels: ol.Bool(false),
})
autopilot.Ok(t, err)
autopilot.Equals(t, name, sc.Name)
autopilot.Equals(t, description, sc.Description)
autopilot.Equals(t, *fakeOwnerId, sc.Owner.Id())
autopilot.Equals(t, *fakeFilterId, sc.Filter.Id)
autopilot.Equals(t, false, sc.AffectsOverallServiceLevels)
}
func TestUpdateScorecard(t *testing.T) {
testRequest := NewTestRequest(
`{{ template "scorecard_update_request" }}`,
`{{ template "scorecard_update_request_vars" }}`,
`{{ template "scorecard_update_response" }}`,
)
name := "updated scorecard"
description := "this scorecard was updated"
client := BestTestClient(t, "scorecards/update_scorecard", testRequest)
sc, err := client.UpdateScorecard(scorecardId, ol.ScorecardInput{
Description: &description,
Name: name,
OwnerId: *newOwnerId,
FilterId: newFilterId,
})
autopilot.Ok(t, err)
autopilot.Equals(t, *ol.NewID(scorecardId), sc.Id)
autopilot.Equals(t, name, sc.Name)
autopilot.Equals(t, description, sc.Description)
autopilot.Equals(t, *newOwnerId, sc.Owner.Id())
autopilot.Equals(t, *newFilterId, sc.Filter.Id)
autopilot.Equals(t, false, sc.AffectsOverallServiceLevels)
}
func TestDeleteScorecard(t *testing.T) {
testRequest := NewTestRequest(
`{{ template "scorecard_delete_request" }}`,
`{{ template "scorecard_delete_request_vars" }}`,
`{{ template "scorecard_delete_response" }}`,
)
client := BestTestClient(t, "scorecards/delete_scorecard", testRequest)
deletedScorecardId, err := client.DeleteScorecard(scorecardId)
autopilot.Ok(t, err)
autopilot.Equals(t, ol.ID(scorecardId), deletedScorecardId)
}
func TestGetScorecard(t *testing.T) {
testRequest := NewTestRequest(
`{{ template "scorecard_get_request" }}`,
`{{ template "scorecard_get_request_vars" }}`,
`{{ template "scorecard_get_response" }}`,
)
name := "fetched scorecard"
description := "hello there!"
client := BestTestClient(t, "scorecards/get_scorecard", testRequest)
sc, err := client.GetScorecard(scorecardId)
autopilot.Ok(t, err)
autopilot.Equals(t, *ol.NewID(scorecardId), sc.Id)
autopilot.Equals(t, name, sc.Name)
autopilot.Equals(t, description, sc.Description)
autopilot.Equals(t, *fakeOwnerId, sc.Owner.Id())
autopilot.Equals(t, *fakeFilterId, sc.Filter.Id)
autopilot.Equals(t, 10, sc.PassingChecks)
autopilot.Equals(t, 20, sc.ServiceCount)
autopilot.Equals(t, 30, sc.ChecksCount)
}
func TestListScorecards(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"{{ template "scorecard_list_query" }}"`,
`{{ template "pagination_initial_query_variables" }}`,
`{ "data": { "account": { "scorecards": { "nodes": [ { {{ template "scorecard_1_response" }} }, { {{ template "scorecard_2_response" }} } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}`,
)
testRequestTwo := NewTestRequest(
`"{{ template "scorecard_list_query" }}"`,
`{{ template "pagination_second_query_variables" }}`,
`{ "data": { "account": { "scorecards": { "nodes": [ { {{ template "scorecard_3_response" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}`,
)
requests := []TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "scorecards/list_scorecards", requests...)
// Act
response, err := client.ListScorecards(nil)
result := response.Nodes
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 3, response.TotalCount)
autopilot.Equals(t, "first scorecard", result[0].Name)
autopilot.Equals(t, ol.ConnectiveEnumAnd, result[0].Filter.Connective)
autopilot.Equals(t, *fakeOwnerId, result[0].Owner.Id())
autopilot.Equals(t, 150, result[0].ServiceCount)
autopilot.Equals(t, "second scorecard", result[1].Name)
autopilot.Equals(t, ol.ConnectiveEnumOr, result[1].Filter.Connective)
autopilot.Equals(t, *fakeOwnerId, result[0].Owner.Id())
autopilot.Equals(t, 22, result[1].ServiceCount)
autopilot.Equals(t, "third scorecard", result[2].Name)
autopilot.Equals(t, ol.Filter{}, result[2].Filter)
autopilot.Equals(t, *newOwnerId, result[2].Owner.Id())
autopilot.Equals(t, 33, result[2].ServiceCount)
}