/
formation_is_deleted.go
80 lines (67 loc) · 2.42 KB
/
formation_is_deleted.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
package asserters
import (
"context"
"testing"
"time"
context_keys "github.com/kyma-incubator/compass/tests/pkg/notifications/context-keys"
testingx "github.com/kyma-incubator/compass/tests/pkg/testing"
"github.com/kyma-incubator/compass/tests/pkg/fixtures"
"github.com/machinebox/graphql"
"github.com/stretchr/testify/require"
)
type FormationIsDeletedAsserter struct {
certSecuredGraphQLClient *graphql.Client
tenantID string
formationName string
timeout time.Duration
tick time.Duration
}
func NewFormationIsDeletedAsserter(certSecuredGraphQLClient *graphql.Client) *FormationIsDeletedAsserter {
return &FormationIsDeletedAsserter{
certSecuredGraphQLClient: certSecuredGraphQLClient,
timeout: eventuallyTimeout,
tick: eventuallyTick,
}
}
func (a *FormationIsDeletedAsserter) WithFormationName(formationName string) *FormationIsDeletedAsserter {
a.formationName = formationName
return a
}
func (a *FormationIsDeletedAsserter) WithTenantID(tenantID string) *FormationIsDeletedAsserter {
a.tenantID = tenantID
return a
}
func (a *FormationIsDeletedAsserter) WithTimeout(timeout time.Duration) *FormationIsDeletedAsserter {
a.timeout = timeout
return a
}
func (a *FormationIsDeletedAsserter) WithTick(tick time.Duration) *FormationIsDeletedAsserter {
a.tick = tick
return a
}
func (a *FormationIsDeletedAsserter) AssertExpectations(t *testing.T, ctx context.Context) {
t.Logf("Asserting formation assignments with eventually...")
var formationName string
if a.formationName != "" {
formationName = a.formationName
} else {
formationName = ctx.Value(context_keys.FormationNameKey).(string)
}
tOnce := testingx.NewOnceLogger(t)
require.Eventually(t, func() (isOkay bool) {
// Get the formations for participant globally
formationPage := fixtures.ListFormationsWithinTenant(t, ctx, a.tenantID, a.certSecuredGraphQLClient)
foundFormation := false
for _, formation := range formationPage.Data {
if formation.Name == formationName {
foundFormation = true
}
}
if foundFormation {
tOnce.Logf("Formation with name %s is not yet deleted", formationName)
return false
}
tOnce.Logf("Successfully asserted formation with name %s is deleted", formationName)
return true
}, a.timeout, a.tick, "Timed out after %s while trying to assert formation with name %s is deleted.", a.timeout, formationName)
}