-
Notifications
You must be signed in to change notification settings - Fork 84
/
formation_visibility.go
68 lines (54 loc) · 2.37 KB
/
formation_visibility.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
package asserters
import (
"context"
"testing"
"github.com/kyma-incubator/compass/tests/director/tests/example"
gql "github.com/kyma-incubator/compass/components/director/pkg/graphql"
"github.com/kyma-incubator/compass/tests/pkg/fixtures"
"github.com/kyma-incubator/compass/tests/pkg/testctx"
"github.com/machinebox/graphql"
"github.com/stretchr/testify/require"
)
type FormationExpectation struct {
FormationName string
AssignmentsCount int
StatusCondition gql.FormationStatusCondition
}
type FormationVisibilityAsserter struct {
certSecuredGraphQLClient *graphql.Client
formationExpectations []*FormationExpectation
participantID string
formations gql.FormationExt
}
func NewFormationVisibilityAsserter(certSecuredGraphQLClient *graphql.Client) *FormationVisibilityAsserter {
return &FormationVisibilityAsserter{
certSecuredGraphQLClient: certSecuredGraphQLClient,
}
}
func (a *FormationVisibilityAsserter) WithFormationExpectations(expectations []*FormationExpectation) *FormationVisibilityAsserter {
a.formationExpectations = expectations
return a
}
func (a *FormationVisibilityAsserter) WithParticipantID(participantID string) *FormationVisibilityAsserter {
a.participantID = participantID
return a
}
func (a *FormationVisibilityAsserter) AssertExpectations(t *testing.T, ctx context.Context) {
// Get the formations for participant globally
var gotFormations []*gql.FormationExt
getFormationsForObjectGlobalReq := fixtures.FixGetFormationsForObjectRequest(a.participantID)
err := testctx.Tc.RunOperationWithoutTenant(ctx, a.certSecuredGraphQLClient, getFormationsForObjectGlobalReq, &gotFormations)
require.NoError(t, err)
example.SaveExample(t, getFormationsForObjectGlobalReq.Query(), "list formations for object global")
require.Len(t, gotFormations, len(a.formationExpectations))
formationsByName := make(map[string]*gql.FormationExt, len(gotFormations))
for _, formation := range gotFormations {
formationsByName[formation.Name] = formation
}
for _, currentFormationExpectations := range a.formationExpectations {
actualFormation, ok := formationsByName[currentFormationExpectations.FormationName]
require.True(t, ok)
require.Equal(t, currentFormationExpectations.StatusCondition, actualFormation.Status.Condition)
require.Len(t, actualFormation.FormationAssignments.Data, currentFormationExpectations.AssignmentsCount)
}
}