forked from OpsLevel/opslevel-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dependencies_test.go
104 lines (96 loc) · 4.77 KB
/
dependencies_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
package opslevel_test
import (
"testing"
ol "github.com/opslevel/opslevel-go/v2023"
"github.com/rocktavious/autopilot/v2023"
)
func TestCreateServiceDependency(t *testing.T) {
// Arrange
testRequest := NewTestRequest(
`"mutation ServiceDependencyCreate($input:ServiceDependencyCreateInput!){serviceDependencyCreate(inputV2: $input){serviceDependency{id,sourceService{id,aliases},destinationService{id,aliases},notes},errors{message,path}}}"`,
`{ "input": { "dependencyKey": { "destinationIdentifier": {"alias": "example_3"}, "sourceIdentifier": {"alias": "example_2"} }, "notes": "An example description" }}`,
`{"data": { "serviceDependencyCreate": { "serviceDependency": {{ template "serviceDependency" }}, "errors": [] } }}`,
)
client := BestTestClient(t, "serviceDependencyCreate", testRequest)
// Act
result, err := client.CreateServiceDependency(ol.ServiceDependencyCreateInput{
Key: ol.ServiceDependencyKey{
Service: *ol.NewIdentifier("example_2"),
DependsOn: *ol.NewIdentifier("example_3"),
},
Notes: "An example description",
})
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, id2, result.Service.Id)
autopilot.Equals(t, id3, result.DependsOn.Id)
autopilot.Equals(t, "An example description", result.Notes)
}
func TestGetServiceDependencies(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"query ServiceDependenciesList($after:String!$first:Int!$service:ID!){account{service(id: $service){dependencies(after: $after, first: $first){edges{id,locked,node{id,aliases},notes},{{ template "pagination_request" }}}}}}"`,
`{ {{ template "first_page_variables" }}, "service": "{{ template "id1_string" }}" }`,
`{"data": {"account": { "service": { "dependencies": { "edges": [ {{ template "serviceDependencyEdge_1" }}, {{ template "serviceDependencyEdge_2" }} ], {{ template "pagination_initial_pageInfo_response" }} }}}}}`,
)
testRequestTwo := NewTestRequest(
`"query ServiceDependenciesList($after:String!$first:Int!$service:ID!){account{service(id: $service){dependencies(after: $after, first: $first){edges{id,locked,node{id,aliases},notes},{{ template "pagination_request" }}}}}}"`,
`{ {{ template "second_page_variables" }}, "service": "{{ template "id1_string" }}" }`,
`{"data": {"account": { "service": { "dependencies": { "edges": [ {{ template "serviceDependencyEdge_3" }} ], {{ template "pagination_second_pageInfo_response" }} }}}}}`,
)
requests := []TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "service/get_dependencies", requests...)
// Act
resource := ol.Service{
ServiceId: ol.ServiceId{
Id: id1,
},
}
resp, err := resource.GetDependencies(client, nil)
result := resp.Edges
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, id1, result[0].Id)
autopilot.Equals(t, id3, result[2].Id)
}
func TestGetServiceDependents(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"query ServiceDependentsList($after:String!$first:Int!$service:ID!){account{service(id: $service){dependents(after: $after, first: $first){edges{id,locked,node{id,aliases},notes},{{ template "pagination_request" }}}}}}"`,
`{ {{ template "first_page_variables" }}, "service": "{{ template "id1_string" }}" }`,
`{"data": {"account": { "service": { "dependents": { "edges": [ {{ template "serviceDependencyEdge_1" }}, {{ template "serviceDependencyEdge_2" }} ], {{ template "pagination_initial_pageInfo_response" }} }}}}}`,
)
testRequestTwo := NewTestRequest(
`"query ServiceDependentsList($after:String!$first:Int!$service:ID!){account{service(id: $service){dependents(after: $after, first: $first){edges{id,locked,node{id,aliases},notes},{{ template "pagination_request" }}}}}}"`,
`{ {{ template "second_page_variables" }}, "service": "{{ template "id1_string" }}" }`,
`{"data": {"account": { "service": { "dependents": { "edges": [ {{ template "serviceDependencyEdge_3" }} ], {{ template "pagination_second_pageInfo_response" }} }}}}}`,
)
requests := []TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "service/get_dependents", requests...)
// Act
resource := ol.Service{
ServiceId: ol.ServiceId{
Id: id1,
},
}
resp, err := resource.GetDependents(client, nil)
result := resp.Edges
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, id1, result[0].Id)
autopilot.Equals(t, id3, result[2].Id)
}
func TestDeleteServiceDependency(t *testing.T) {
// Arrange
testRequest := NewTestRequest(
`"mutation ServiceDependencyDelete($input:DeleteInput!){serviceDependencyDelete(input: $input){errors{message,path}}}"`,
`{ "input": { {{ template "id1" }} } }`,
`{"data": { "serviceDependencyDelete": { "errors": [] }}}`,
)
client := BestTestClient(t, "serviceDependencyDelete", testRequest)
// Act
err := client.DeleteServiceDependency(id1)
// Assert
autopilot.Ok(t, err)
}