-
Notifications
You must be signed in to change notification settings - Fork 13
/
secrets_test.go
103 lines (93 loc) · 3.81 KB
/
secrets_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
package opslevel_test
import (
"testing"
"github.com/opslevel/opslevel-go/v2024"
"github.com/rocktavious/autopilot/v2023"
)
func TestCreateSecret(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation SecretsVaultsSecretCreate($alias:String!$input:SecretInput!){secretsVaultsSecretCreate(alias: $alias, input: $input){secret{alias,id,owner{alias,id},timestamps{createdAt,updatedAt}},errors{message,path}}}`,
`{{ template "secret_create_vars" }}`,
`{{ template "secret_create_response" }}`,
)
client := BestTestClient(t, "secrets/create", testRequest)
// Act
secretInput := opslevel.SecretInput{
Owner: opslevel.NewIdentifier(string(id2)),
Value: opslevel.RefOf("my-secret"),
}
result, err := client.CreateSecret("alias1", secretInput)
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, id2, result.Owner.Id)
}
func TestGetSecret(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query SecretsVaultsSecret($input:IdentifierInput!){account{secretsVaultsSecret(input: $input){alias,id,owner{alias,id},timestamps{createdAt,updatedAt}}}}`,
`{{ template "secret_get_vars" }}`,
`{{ template "secret_get_response" }}`,
)
client := BestTestClient(t, "secret/get", testRequest)
// Act
result, err := client.GetSecret(string(id2))
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id2, result.ID)
}
func TestListSecrets(t *testing.T) {
// Arrange
testRequestOne := autopilot.NewTestRequest(
`query SecretList($after:String!$first:Int!){account{secretsVaultsSecrets(after: $after, first: $first){nodes{alias,id,owner{alias,id},timestamps{createdAt,updatedAt}},{{ template "pagination_request" }}}}}`,
`{{ template "pagination_initial_query_variables" }}`,
`{{ template "secret_list_response_1" }}`,
)
testRequestTwo := autopilot.NewTestRequest(
`query SecretList($after:String!$first:Int!){account{secretsVaultsSecrets(after: $after, first: $first){nodes{alias,id,owner{alias,id},timestamps{createdAt,updatedAt}},{{ template "pagination_request" }}}}}`,
`{{ template "pagination_second_query_variables" }}`,
`{{ template "secret_list_response_2" }}`,
)
requests := []autopilot.TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "secrets/list", requests...)
// Act
secretsVaultsSecretConnection, err := client.ListSecretsVaultsSecret(nil)
secretNode := secretsVaultsSecretConnection.Nodes
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 3, secretsVaultsSecretConnection.TotalCount)
autopilot.Equals(t, "example_2", secretNode[1].Alias)
autopilot.Equals(t, secretNode[1].Alias, secretNode[1].Owner.Alias)
}
func TestUpdateSecret(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation SecretsVaultsSecretUpdate($input:SecretInput!$secret:IdentifierInput!){secretsVaultsSecretUpdate(input: $input, secret: $secret){secret{alias,id,owner{alias,id},timestamps{createdAt,updatedAt}},errors{message,path}}}`,
`{{ template "secret_update_vars" }}`,
`{{ template "secret_update_response" }}`,
)
client := BestTestClient(t, "secrets/update", testRequest)
// Act
secretInput := opslevel.SecretInput{
Owner: opslevel.NewIdentifier(string(id2)),
Value: opslevel.RefOf("secret_value_2"),
}
result, err := client.UpdateSecret(string(id2), secretInput)
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, id2, result.ID)
autopilot.Equals(t, id2, result.Owner.Id)
}
func TestDeleteSecrets(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation SecretsVaultsSecretDelete($input:IdentifierInput!){secretsVaultsSecretDelete(resource: $input){errors{message,path}}}`,
`{{ template "secret_delete_vars" }}`,
`{{ template "secret_delete_response" }}`,
)
client := BestTestClient(t, "secrets/delete", testRequest)
// Act
err := client.DeleteSecret(string(id1))
// Assert
autopilot.Equals(t, nil, err)
}