-
Notifications
You must be signed in to change notification settings - Fork 6
/
template_credentials_test.go
101 lines (90 loc) · 3.21 KB
/
template_credentials_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
package transloadit
import (
"reflect"
"testing"
)
func TestTemplateCredentials(t *testing.T) {
t.Parallel()
client := setup(t)
templateCredentialName := generateTemplateName()
templateCredentialPost := NewTemplateCredential()
templateCredentialPost.Name = templateCredentialName
templateCredentialPost.Type = "s3"
templateCredentialContent := map[string]interface{}{
"key": "xyxy",
"secret": "xyxyxyxy",
"bucket": "mybucket.example.com",
"bucket_region": "us-east-1",
}
templateCredentialPost.Content = templateCredentialContent
// Step 1: Create a brand new templateCredential
id, err := client.CreateTemplateCredential(ctx, templateCredentialPost)
if err != nil {
t.Error(err)
}
if id == "" {
t.Error("no templateCredentialPost id returned")
}
// Step 2: Retrieve new templateCredential created and assert its properties
var templateCredential TemplateCredential
if templateCredential, err = client.GetTemplateCredential(ctx, id); err != nil {
t.Error(err)
}
checkTemplateCredential(t, templateCredential, templateCredentialName, templateCredentialContent)
// Step 3: List all Templated credentials and assume that the created templateCredential is present
list, err := client.ListTemplateCredential(ctx, nil)
if err != nil {
t.Error(err)
}
found := false
for _, cred := range list.TemplateCredential {
if cred.ID == id {
checkTemplateCredential(t, cred, templateCredentialName, templateCredentialContent)
found = true
}
}
if !found {
t.Errorf("Created TemplateCredential not found id=%s", id)
}
// Step 4 : Update the Template credential
newTemplateCredentialPost := NewTemplateCredential()
newtemplateCredentialName := templateCredentialName + "updated"
newTemplateCredentialPost.Name = newtemplateCredentialName
newTemplateCredentialPost.Type = "backblaze"
newtemplateCredentialContent := map[string]interface{}{
"bucket": "mybucket",
"app_key_id": "mykeyid",
"app_key": "mykey",
}
newTemplateCredentialPost.Content = newtemplateCredentialContent
err = client.UpdateTemplateCredential(ctx, id, newTemplateCredentialPost)
if err != nil {
t.Error(err)
}
// Step 5 : Check the updated Template credential
var newTemplateCredential TemplateCredential
if newTemplateCredential, err = client.GetTemplateCredential(ctx, id); err != nil {
t.Error(err)
}
checkTemplateCredential(t, newTemplateCredential, newtemplateCredentialName, newtemplateCredentialContent)
// Step 6: Delete test templateCredential
if err := client.DeleteTemplateCredential(ctx, id); err != nil {
t.Error(err)
}
// Step 7: Assert templateCredential has been deleted
_, err = client.GetTemplateCredential(ctx, id)
if err.(RequestError).Code != "TEMPLATE_CREDENTIALS_NOT_READ" {
t.Error("templateCredentialPost has not been deleted")
}
}
func checkTemplateCredential(t *testing.T, cred TemplateCredential, templateCredentialName string, expected map[string]interface{}) {
if cred.Name != templateCredentialName {
t.Error("wrong templateCredentialPost name")
}
if cred.Type != "s3" {
t.Error("wrong templateCredentialPost type")
}
if !reflect.DeepEqual(cred.Content, expected) {
t.Errorf("Different in content expected=%+v . In response : %+v", expected, cred.Content)
}
}