/
formation_template_queries.go
190 lines (144 loc) · 8.52 KB
/
formation_template_queries.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package fixtures
import (
"context"
"testing"
"github.com/kyma-incubator/compass/components/director/pkg/graphql"
"github.com/kyma-incubator/compass/tests/pkg/assertions"
"github.com/kyma-incubator/compass/tests/pkg/testctx"
gcli "github.com/machinebox/graphql"
"github.com/stretchr/testify/require"
)
func CreateFormationTemplate(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, in graphql.FormationTemplateInput) graphql.FormationTemplate {
formationTemplateInputGQLString, err := testctx.Tc.Graphqlizer.FormationTemplateInputToGQL(in)
require.NoError(t, err)
createRequest := FixCreateFormationTemplateRequest(formationTemplateInputGQLString)
formationTemplate := graphql.FormationTemplate{}
require.NoError(t, testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, createRequest, &formationTemplate))
require.NotEmpty(t, formationTemplate.ID)
return formationTemplate
}
func CreateFormationTemplateExpectError(t *testing.T, ctx context.Context, gqlClient *gcli.Client, in graphql.FormationTemplateInput) {
formationTemplateInputGQLString, err := testctx.Tc.Graphqlizer.FormationTemplateInputToGQL(in)
require.NoError(t, err)
createRequest := FixCreateFormationTemplateRequest(formationTemplateInputGQLString)
formationTemplate := graphql.FormationTemplate{}
err = testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, createRequest, &formationTemplate)
// In case of successfully created formation template the require statement terminates the test case and the ID is not returned. Should clean up the formation template here.
if formationTemplate.ID != "" {
defer CleanupFormationTemplate(t, ctx, gqlClient, &formationTemplate)
}
require.Error(t, err)
t.Log("Error: ", err.Error())
}
func CreateFormationTemplateWithTenant(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, tenant string, in graphql.FormationTemplateInput) graphql.FormationTemplate {
formationTemplateInputGQLString, err := testctx.Tc.Graphqlizer.FormationTemplateInputToGQL(in)
require.NoError(t, err)
createRequest := FixCreateFormationTemplateRequest(formationTemplateInputGQLString)
formationTemplate := graphql.FormationTemplate{}
require.NoError(t, testctx.Tc.RunOperationWithCustomTenant(ctx, gqlClient, tenant, createRequest, &formationTemplate))
require.NotEmpty(t, formationTemplate.ID)
return formationTemplate
}
func CreateFormationTemplateWithoutInput(t *testing.T, ctx context.Context, gqlClient *gcli.Client, formationTemplateName, runtimeType string, applicationTypes []string, runtimeArtifactKind graphql.ArtifactType) graphql.FormationTemplate {
formationTmplInput := graphql.FormationTemplateInput{
Name: formationTemplateName,
ApplicationTypes: applicationTypes,
RuntimeTypes: []string{runtimeType},
RuntimeTypeDisplayName: &formationTemplateName,
RuntimeArtifactKind: &runtimeArtifactKind,
}
formationTmplGQLInput, err := testctx.Tc.Graphqlizer.FormationTemplateInputToGQL(formationTmplInput)
require.NoError(t, err)
formationTmplRequest := FixCreateFormationTemplateRequest(formationTmplGQLInput)
ft := graphql.FormationTemplate{}
t.Logf("Creating formation template with name: %q", formationTemplateName)
err = testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, formationTmplRequest, &ft)
require.NoError(t, err)
return ft
}
func CreateAppOnlyFormationTemplateWithoutInput(t *testing.T, ctx context.Context, gqlClient *gcli.Client, formationTemplateName string, applicationTypes []string, leadingProductIDs []string, supportsReset bool) graphql.FormationTemplate {
formationTmplInput := graphql.FormationTemplateInput{
Name: formationTemplateName,
ApplicationTypes: applicationTypes,
LeadingProductIDs: leadingProductIDs,
SupportsReset: &supportsReset,
}
formationTmplGQLInput, err := testctx.Tc.Graphqlizer.FormationTemplateInputToGQL(formationTmplInput)
require.NoError(t, err)
formationTmplRequest := FixCreateFormationTemplateRequest(formationTmplGQLInput)
ft := graphql.FormationTemplate{}
t.Logf("Creating formation template with name: %q", formationTemplateName)
err = testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, formationTmplRequest, &ft)
require.NoError(t, err)
return ft
}
func CreateFormationTemplateWithLeadingProductIDs(t *testing.T, ctx context.Context, gqlClient *gcli.Client, formationTemplateName, runtimeType string, applicationTypes []string, runtimeArtifactKind graphql.ArtifactType, leadingProductIDs []string) graphql.FormationTemplate {
formationTmplInput := FixFormationTemplateInputWithLeadingProductIDs(formationTemplateName, applicationTypes, []string{runtimeType}, runtimeArtifactKind, leadingProductIDs)
formationTmplGQLInput, err := testctx.Tc.Graphqlizer.FormationTemplateInputToGQL(formationTmplInput)
require.NoError(t, err)
formationTmplRequest := FixCreateFormationTemplateRequest(formationTmplGQLInput)
ft := graphql.FormationTemplate{}
t.Logf("Creating formation template with name: %q", formationTemplateName)
err = testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, formationTmplRequest, &ft)
require.NoError(t, err)
return ft
}
func QueryFormationTemplate(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, id string) *graphql.FormationTemplate {
queryRequest := FixQueryFormationTemplateRequest(id)
formationTemplate := graphql.FormationTemplate{}
require.NoError(t, testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, queryRequest, &formationTemplate))
require.NotEmpty(t, formationTemplate.ID)
return &formationTemplate
}
func QueryFormationTemplateWithConstraints(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, id string) *graphql.FormationTemplateExt {
queryRequest := FixQueryFormationTemplateWithConstraintsRequest(id)
formationTemplate := graphql.FormationTemplateExt{}
require.NoError(t, testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, queryRequest, &formationTemplate))
require.NotEmpty(t, formationTemplate.ID)
return &formationTemplate
}
func QueryFormationTemplatesWithPageSize(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, pageSize int) *graphql.FormationTemplatePage {
queryPaginationRequest := FixQueryFormationTemplatesRequestWithPageSize(pageSize)
var formationTemplates graphql.FormationTemplatePage
require.NoError(t, testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, queryPaginationRequest, &formationTemplates))
require.NotEmpty(t, formationTemplates)
return &formationTemplates
}
func QueryFormationTemplatesWithPageSizeAndTenant(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, pageSize int, tenantID string) *graphql.FormationTemplatePage {
queryPaginationRequest := FixQueryFormationTemplatesRequestWithPageSize(pageSize)
var formationTemplates graphql.FormationTemplatePage
require.NoError(t, testctx.Tc.RunOperationWithCustomTenant(ctx, gqlClient, tenantID, queryPaginationRequest, &formationTemplates))
require.NotEmpty(t, formationTemplates)
return &formationTemplates
}
func CleanupFormationTemplate(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, template *graphql.FormationTemplate) *graphql.FormationTemplate {
if template == nil {
return &graphql.FormationTemplate{}
}
deleteRequest := FixDeleteFormationTemplateRequest(template.ID)
formationTemplate := graphql.FormationTemplate{}
err := testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, deleteRequest, &formationTemplate)
assertions.AssertNoErrorForOtherThanNotFound(t, err)
return &formationTemplate
}
func UpdateFormationTemplateExpectError(t *testing.T, ctx context.Context, gqlClient *gcli.Client, id string, in graphql.FormationTemplateInput) {
updatedFormationTemplateInputGQLString, err := testctx.Tc.Graphqlizer.FormationTemplateInputToGQL(in)
require.NoError(t, err)
updateFormationTemplateRequest := FixUpdateFormationTemplateRequest(id, updatedFormationTemplateInputGQLString)
output := graphql.FormationTemplate{}
// WHEN
err = testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, updateFormationTemplateRequest, &output)
//THEN
require.Error(t, err)
t.Log("Error: ", err.Error())
}
func CleanupFormationTemplateWithTenant(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, tenant string, template *graphql.FormationTemplate) *graphql.FormationTemplate {
if template == nil {
return &graphql.FormationTemplate{}
}
deleteRequest := FixDeleteFormationTemplateRequest(template.ID)
formationTemplate := graphql.FormationTemplate{}
err := testctx.Tc.RunOperationWithCustomTenant(ctx, gqlClient, tenant, deleteRequest, &formationTemplate)
assertions.AssertNoErrorForOtherThanNotFound(t, err)
return &formationTemplate
}