github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/formationconstraint/fixtures_test.go (about)

     1  package formationconstraint_test
     2  
     3  import (
     4  	"github.com/kyma-incubator/compass/components/director/internal/domain/formationconstraint"
     5  	"github.com/kyma-incubator/compass/components/director/internal/domain/formationconstraint/automock"
     6  	"github.com/kyma-incubator/compass/components/director/internal/domain/formationconstraint/operators"
     7  	"github.com/kyma-incubator/compass/components/director/internal/model"
     8  	formationconstraintpkg "github.com/kyma-incubator/compass/components/director/pkg/formationconstraint"
     9  	"github.com/kyma-incubator/compass/components/director/pkg/graphql"
    10  )
    11  
    12  const (
    13  	testID                  = "d1fddec6-5456-4a1e-9ae0-74447f5d6ae9"
    14  	formationTemplateID     = "id"
    15  	formationConstraintName = "test constraint"
    16  	operatorName            = operators.IsNotAssignedToAnyFormationOfTypeOperator
    17  	resourceSubtype         = "test subtype"
    18  	resourceSubtypeANY      = "ANY"
    19  	inputTemplate           = `{"formation_template_id": "{{.FormationTemplateID}}","resource_type": "{{.ResourceType}}","resource_subtype": "{{.ResourceSubtype}}","resource_id": "{{.ResourceID}}","tenant": "{{.TenantID}}"}`
    20  	inputTemplateUpdated    = `{"formation_template_id": "{{.FormationTemplateID}}","resource_type": "{{.ResourceType}}","resource_subtype": "{{.ResourceSubtype}}","resource_id": "{{.ResourceID}}","tenant": "{{.TenantID}}", "newField": "value"}`
    21  	testTenantID            = "d9fddec6-5456-4a1e-9ae0-74447f5d6ae9"
    22  	testName                = "test"
    23  )
    24  
    25  var (
    26  	formationConstraintModel = &model.FormationConstraint{
    27  		ID:              testID,
    28  		Name:            formationConstraintName,
    29  		ConstraintType:  model.PreOperation,
    30  		TargetOperation: model.AssignFormationOperation,
    31  		Operator:        operatorName,
    32  		ResourceType:    model.ApplicationResourceType,
    33  		ResourceSubtype: resourceSubtype,
    34  		InputTemplate:   inputTemplate,
    35  		ConstraintScope: model.FormationTypeFormationConstraintScope,
    36  	}
    37  	formationConstraintModelUpdated = &model.FormationConstraint{
    38  		ID:              testID,
    39  		Name:            formationConstraintName,
    40  		ConstraintType:  model.PreOperation,
    41  		TargetOperation: model.AssignFormationOperation,
    42  		Operator:        operatorName,
    43  		ResourceType:    model.ApplicationResourceType,
    44  		ResourceSubtype: resourceSubtype,
    45  		InputTemplate:   inputTemplateUpdated,
    46  		ConstraintScope: model.FormationTypeFormationConstraintScope,
    47  	}
    48  	gqlFormationConstraint = &graphql.FormationConstraint{
    49  		ID:              testID,
    50  		Name:            formationConstraintName,
    51  		ConstraintType:  string(model.PreOperation),
    52  		TargetOperation: string(model.AssignFormationOperation),
    53  		Operator:        operatorName,
    54  		ResourceType:    string(model.ApplicationResourceType),
    55  		ResourceSubtype: resourceSubtype,
    56  		InputTemplate:   inputTemplate,
    57  		ConstraintScope: string(model.FormationTypeFormationConstraintScope),
    58  	}
    59  	gqlFormationConstraintUpdated = &graphql.FormationConstraint{
    60  		ID:              testID,
    61  		Name:            formationConstraintName,
    62  		ConstraintType:  string(model.PreOperation),
    63  		TargetOperation: string(model.AssignFormationOperation),
    64  		Operator:        operatorName,
    65  		ResourceType:    string(model.ApplicationResourceType),
    66  		ResourceSubtype: resourceSubtype,
    67  		InputTemplate:   inputTemplateUpdated,
    68  		ConstraintScope: string(model.FormationTypeFormationConstraintScope),
    69  	}
    70  	formationConstraintModel2 = &model.FormationConstraint{
    71  		ID:              testID,
    72  		Name:            formationConstraintName,
    73  		ConstraintType:  model.PostOperation,
    74  		TargetOperation: model.AssignFormationOperation,
    75  		Operator:        operatorName,
    76  		ResourceType:    model.ApplicationResourceType,
    77  		ResourceSubtype: resourceSubtype,
    78  		InputTemplate:   inputTemplate,
    79  		ConstraintScope: model.FormationTypeFormationConstraintScope,
    80  	}
    81  	gqlFormationConstraint2 = &graphql.FormationConstraint{
    82  		ID:              testID,
    83  		Name:            formationConstraintName,
    84  		ConstraintType:  string(model.PostOperation),
    85  		TargetOperation: string(model.AssignFormationOperation),
    86  		Operator:        operatorName,
    87  		ResourceType:    string(model.ApplicationResourceType),
    88  		ResourceSubtype: resourceSubtype,
    89  		InputTemplate:   inputTemplate,
    90  		ConstraintScope: string(model.FormationTypeFormationConstraintScope),
    91  	}
    92  	formationConstraintInput = graphql.FormationConstraintInput{
    93  		Name:            formationConstraintName,
    94  		ConstraintType:  graphql.ConstraintTypePre,
    95  		TargetOperation: graphql.TargetOperationAssignFormation,
    96  		Operator:        operatorName,
    97  		ResourceType:    graphql.ResourceTypeApplication,
    98  		ResourceSubtype: resourceSubtype,
    99  		InputTemplate:   inputTemplate,
   100  		ConstraintScope: graphql.ConstraintScopeFormationType,
   101  	}
   102  	formationConstraintInputUpdated = graphql.FormationConstraintInput{
   103  		Name:            formationConstraintName,
   104  		ConstraintType:  graphql.ConstraintTypePre,
   105  		TargetOperation: graphql.TargetOperationAssignFormation,
   106  		Operator:        operatorName,
   107  		ResourceType:    graphql.ResourceTypeApplication,
   108  		ResourceSubtype: resourceSubtype,
   109  		InputTemplate:   inputTemplateUpdated,
   110  		ConstraintScope: graphql.ConstraintScopeFormationType,
   111  	}
   112  	formationConstraintModelInput = &model.FormationConstraintInput{
   113  		Name:            formationConstraintName,
   114  		ConstraintType:  model.PreOperation,
   115  		TargetOperation: model.AssignFormationOperation,
   116  		Operator:        operatorName,
   117  		ResourceType:    model.ApplicationResourceType,
   118  		ResourceSubtype: resourceSubtype,
   119  		InputTemplate:   inputTemplate,
   120  		ConstraintScope: model.FormationTypeFormationConstraintScope,
   121  	}
   122  	formationConstraintUpdateInput = graphql.FormationConstraintUpdateInput{
   123  		InputTemplate: inputTemplateUpdated,
   124  	}
   125  	entity = formationconstraint.Entity{
   126  		ID:              testID,
   127  		Name:            formationConstraintName,
   128  		ConstraintType:  string(model.PreOperation),
   129  		TargetOperation: string(model.AssignFormationOperation),
   130  		Operator:        operatorName,
   131  		ResourceType:    string(model.ApplicationResourceType),
   132  		ResourceSubtype: resourceSubtype,
   133  		InputTemplate:   inputTemplate,
   134  		ConstraintScope: string(model.FormationTypeFormationConstraintScope),
   135  	}
   136  	nilModelEntity               *model.FormationConstraint
   137  	formationConstraintReference = &model.FormationTemplateConstraintReference{
   138  		ConstraintID:        testID,
   139  		FormationTemplateID: formationTemplateID,
   140  	}
   141  	location = formationconstraintpkg.JoinPointLocation{
   142  		OperationName:  "assign",
   143  		ConstraintType: "pre",
   144  	}
   145  	details = formationconstraintpkg.AssignFormationOperationDetails{
   146  		ResourceType:    "runtime",
   147  		ResourceSubtype: "kyma",
   148  	}
   149  	matchingDetails = details.GetMatchingDetails()
   150  
   151  	gqlInput       = &graphql.FormationConstraintInput{Name: testName}
   152  	modelInput     = &model.FormationConstraintInput{Name: testName}
   153  	modelFromInput = &model.FormationConstraint{ID: testID, Name: testName}
   154  
   155  	formationTemplateID1 = "123"
   156  	formationTemplateID2 = "456"
   157  	formationTemplateID3 = "789"
   158  	constraintID1        = "constraintID1"
   159  	constraintID2        = "constraintID2"
   160  	constraintID3        = "constraintID3"
   161  
   162  	formationConstraint1 = &model.FormationConstraint{
   163  		ID:              constraintID1,
   164  		Name:            formationConstraintName,
   165  		ConstraintType:  model.PreOperation,
   166  		TargetOperation: model.AssignFormationOperation,
   167  		Operator:        operatorName,
   168  		ResourceType:    model.ApplicationResourceType,
   169  		ResourceSubtype: resourceSubtype,
   170  		InputTemplate:   inputTemplate,
   171  		ConstraintScope: model.FormationTypeFormationConstraintScope,
   172  	}
   173  	formationConstraint2 = &model.FormationConstraint{
   174  		ID:              constraintID2,
   175  		Name:            formationConstraintName,
   176  		ConstraintType:  model.PreOperation,
   177  		TargetOperation: model.AssignFormationOperation,
   178  		Operator:        operatorName,
   179  		ResourceType:    model.ApplicationResourceType,
   180  		ResourceSubtype: resourceSubtype,
   181  		InputTemplate:   inputTemplate,
   182  		ConstraintScope: model.FormationTypeFormationConstraintScope,
   183  	}
   184  	globalConstraint = &model.FormationConstraint{
   185  		ID:              constraintID3,
   186  		Name:            formationConstraintName,
   187  		ConstraintType:  model.PreOperation,
   188  		TargetOperation: model.AssignFormationOperation,
   189  		Operator:        operatorName,
   190  		ResourceType:    model.ApplicationResourceType,
   191  		ResourceSubtype: resourceSubtype,
   192  		InputTemplate:   inputTemplate,
   193  		ConstraintScope: model.GlobalFormationConstraintScope,
   194  	}
   195  )
   196  
   197  func UnusedFormationConstraintService() *automock.FormationConstraintService {
   198  	return &automock.FormationConstraintService{}
   199  }
   200  
   201  func UnusedFormationConstraintRepository() *automock.FormationConstraintRepository {
   202  	return &automock.FormationConstraintRepository{}
   203  }
   204  
   205  func UnusedFormationConstraintConverter() *automock.FormationConstraintConverter {
   206  	return &automock.FormationConstraintConverter{}
   207  }
   208  
   209  func fixColumns() []string {
   210  	return []string{"id", "name", "constraint_type", "target_operation", "operator", "resource_type", "resource_subtype", "input_template", "constraint_scope"}
   211  }