forked from OpsLevel/opslevel-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools_test.go
64 lines (59 loc) · 2.21 KB
/
tools_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
package opslevel_test
import (
"testing"
ol "github.com/opslevel/opslevel-go/v2023"
"github.com/rocktavious/autopilot/v2023"
)
func TestCreateTool(t *testing.T) {
// Arrange
testRequest := NewTestRequest(
`"mutation ToolCreate($input:ToolCreateInput!){toolCreate(input: $input){tool{category,categoryAlias,displayName,environment,id,url,service{id,aliases}},errors{message,path}}}"`,
`{ "input": { "category": "other", "displayName": "example", "serviceId": "{{ template "id1_string" }}", "url": "https://example.com" }}`,
`{"data": { "toolCreate": { "tool": {{ template "tool_1" }}, "errors": [] }}}`,
)
client := BestTestClient(t, "toolCreate", testRequest)
// Act
result, err := client.CreateTool(ol.ToolCreateInput{
Category: ol.ToolCategoryOther,
DisplayName: "example",
ServiceId: id1,
Url: "https://example.com",
})
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, id1, result.Service.Id)
autopilot.Equals(t, ol.ToolCategoryOther, result.Category)
autopilot.Equals(t, "Example", result.DisplayName)
autopilot.Equals(t, "https://example.com", result.Url)
}
func TestUpdateTool(t *testing.T) {
// Arrange
testRequest := NewTestRequest(
`"mutation ToolUpdate($input:ToolUpdateInput!){toolUpdate(input: $input){tool{category,categoryAlias,displayName,environment,id,url,service{id,aliases}},errors{message,path}}}"`,
`{ "input": { {{ template "id1" }}, "category": "deployment" }}`,
`{"data": { "toolUpdate": { "tool": {{ template "tool_1_update" }}, "errors": [] }}}`,
)
client := BestTestClient(t, "toolUpdate", testRequest)
// Act
result, err := client.UpdateTool(ol.ToolUpdateInput{
Id: id1,
Category: ol.ToolCategoryDeployment,
})
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, ol.ToolCategoryDeployment, result.Category)
autopilot.Equals(t, "prod", result.Environment)
}
func TestDeleteTool(t *testing.T) {
// Arrange
testRequest := NewTestRequest(
`"mutation ToolDelete($input:ToolDeleteInput!){toolDelete(input: $input){errors{message,path}}}"`,
`{ "input": { {{ template "id1" }} } }`,
`{"data": { "toolDelete": { "errors": [] }}}`,
)
client := BestTestClient(t, "toolDelete", testRequest)
// Act
err := client.DeleteTool(id1)
// Assert
autopilot.Ok(t, err)
}