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

     1  package datainputbuilder_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	"github.com/kyma-incubator/compass/components/director/internal/domain/webhook/datainputbuilder/automock"
     8  	"github.com/kyma-incubator/compass/components/director/internal/model"
     9  	"github.com/kyma-incubator/compass/components/director/pkg/str"
    10  	"github.com/kyma-incubator/compass/components/director/pkg/webhook"
    11  )
    12  
    13  const (
    14  	ScenarioName            = "scenario-A"
    15  	Tnt                     = "953ac686-5773-4ad0-8eb1-2349e931f852"
    16  	RuntimeID               = "rt-id"
    17  	RuntimeContextRuntimeID = "rt-ctx-rt-id"
    18  	RuntimeContextID        = "rt-ctx-id"
    19  	RuntimeContext2ID       = "rt-ctx-id-2"
    20  	ApplicationID           = "04f3568d-3e0c-4f6b-b646-e6979e9d060c"
    21  	Application2ID          = "6f5389cf-4f9e-46b3-9870-624d792d94ad"
    22  	ApplicationTemplateID   = "58963c6f-24f6-4128-a05c-51d5356e7e09"
    23  )
    24  
    25  var (
    26  	applicationMappings = map[string]*webhook.ApplicationWithLabels{
    27  		ApplicationID: {
    28  			Application: fixApplicationModel(ApplicationID),
    29  			Labels:      fixLabelsMapForApplicationWithLabels(),
    30  		},
    31  		Application2ID: {
    32  			Application: fixApplicationModelWithoutTemplate(Application2ID),
    33  			Labels:      fixLabelsMapForApplicationWithLabels(),
    34  		},
    35  	}
    36  
    37  	applicationMappingsWithCompositeLabel = map[string]*webhook.ApplicationWithLabels{
    38  		ApplicationID: {
    39  			Application: fixApplicationModel(ApplicationID),
    40  			Labels:      fixLabelsMapForApplicationWithCompositeLabels(),
    41  		},
    42  		Application2ID: {
    43  			Application: fixApplicationModelWithoutTemplate(Application2ID),
    44  			Labels:      fixLabelsMapForApplicationWithLabels(),
    45  		},
    46  	}
    47  
    48  	applicationTemplateMappings = map[string]*webhook.ApplicationTemplateWithLabels{
    49  		ApplicationTemplateID: {
    50  			ApplicationTemplate: fixApplicationTemplateModel(),
    51  			Labels:              fixLabelsMapForApplicationTemplateWithLabels(),
    52  		},
    53  	}
    54  
    55  	runtimeMappings = map[string]*webhook.RuntimeWithLabels{
    56  		RuntimeContextRuntimeID: {
    57  			Runtime: fixRuntimeModel(RuntimeContextRuntimeID),
    58  			Labels:  fixLabelsMapForRuntimeWithLabels(),
    59  		},
    60  		RuntimeID: {
    61  			Runtime: fixRuntimeModel(RuntimeID),
    62  			Labels:  fixLabelsMapForRuntimeWithLabels(),
    63  		},
    64  	}
    65  
    66  	runtimeContextMappings = map[string]*webhook.RuntimeContextWithLabels{
    67  		RuntimeContextRuntimeID: {
    68  			RuntimeContext: fixRuntimeContextModel(),
    69  			Labels:         fixLabelsMapForRuntimeContextWithLabels(),
    70  		},
    71  		RuntimeID: {
    72  			RuntimeContext: fixRuntimeContextModelWithRuntimeID(RuntimeID),
    73  			Labels:         fixLabelsMapForRuntimeContextWithLabels(),
    74  		},
    75  	}
    76  )
    77  
    78  func fixApplicationLabelsMap() map[string]interface{} {
    79  	return map[string]interface{}{
    80  		"app-label-key": "app-label-value",
    81  	}
    82  }
    83  
    84  func fixApplicationLabelsMapWithUnquotableLabels() map[string]interface{} {
    85  	return map[string]interface{}{
    86  		"app-label-key": []string{"app-label-value"},
    87  	}
    88  }
    89  
    90  func fixLabelsMapForApplicationWithLabels() map[string]string {
    91  	return map[string]string{
    92  		"app-label-key": "app-label-value",
    93  	}
    94  }
    95  
    96  func fixLabelsMapForApplicationWithCompositeLabels() map[string]string {
    97  	return map[string]string{
    98  		"app-label-key": "[\"app-label-value\"]",
    99  	}
   100  }
   101  
   102  func fixApplicationTemplateLabelsMap() map[string]interface{} {
   103  	return map[string]interface{}{
   104  		"apptemplate-label-key": "apptemplate-label-value",
   105  	}
   106  }
   107  
   108  func fixLabelsMapForApplicationTemplateWithLabels() map[string]string {
   109  	return map[string]string{
   110  		"apptemplate-label-key": "apptemplate-label-value",
   111  	}
   112  }
   113  
   114  func fixRuntimeModel(runtimeID string) *model.Runtime {
   115  	return &model.Runtime{
   116  		ID:                runtimeID,
   117  		Name:              "runtime name",
   118  		Description:       str.Ptr("some description"),
   119  		CreationTimestamp: time.Time{},
   120  	}
   121  }
   122  
   123  func fixRuntimeContextModel() *model.RuntimeContext {
   124  	return &model.RuntimeContext{
   125  		ID:        RuntimeContextID,
   126  		RuntimeID: RuntimeContextRuntimeID,
   127  		Key:       "some-key",
   128  		Value:     "some-value",
   129  	}
   130  }
   131  
   132  func fixRuntimeContextModelWithRuntimeID(rtID string) *model.RuntimeContext {
   133  	return &model.RuntimeContext{
   134  		ID:        RuntimeContext2ID,
   135  		RuntimeID: rtID,
   136  		Key:       "some-key",
   137  		Value:     "some-value",
   138  	}
   139  }
   140  
   141  func fixRuntimeLabelsMap() map[string]interface{} {
   142  	return map[string]interface{}{
   143  		"runtime-label-key": "runtime-label-value",
   144  	}
   145  }
   146  
   147  func fixLabelsMapForRuntimeWithLabels() map[string]string {
   148  	return map[string]string{
   149  		"runtime-label-key": "runtime-label-value",
   150  	}
   151  }
   152  
   153  func fixRuntimeContextLabelsMap() map[string]interface{} {
   154  	return map[string]interface{}{
   155  		"runtime-context-label-key": "runtime-context-label-value",
   156  	}
   157  }
   158  
   159  func fixLabelsMapForRuntimeContextWithLabels() map[string]string {
   160  	return map[string]string{
   161  		"runtime-context-label-key": "runtime-context-label-value",
   162  	}
   163  }
   164  
   165  func fixApplicationModel(applicationID string) *model.Application {
   166  	return &model.Application{
   167  		ProviderName:          str.Ptr("application-provider"),
   168  		ApplicationTemplateID: str.Ptr(ApplicationTemplateID),
   169  		Name:                  "application-name",
   170  		Description:           str.Ptr("detailed application description"),
   171  		Status: &model.ApplicationStatus{
   172  			Condition: model.ApplicationStatusConditionInitial,
   173  			Timestamp: time.Time{},
   174  		},
   175  		HealthCheckURL:      str.Ptr("localhost/healthz"),
   176  		BaseURL:             str.Ptr("base_url"),
   177  		OrdLabels:           json.RawMessage("[]"),
   178  		CorrelationIDs:      json.RawMessage("[]"),
   179  		SystemStatus:        str.Ptr("reachable"),
   180  		DocumentationLabels: json.RawMessage("[]"),
   181  		BaseEntity: &model.BaseEntity{
   182  			ID:        applicationID,
   183  			Ready:     true,
   184  			Error:     nil,
   185  			CreatedAt: &time.Time{},
   186  			UpdatedAt: &time.Time{},
   187  			DeletedAt: &time.Time{},
   188  		},
   189  	}
   190  }
   191  
   192  func fixApplicationModelWithoutTemplate(applicationID string) *model.Application {
   193  	appModel := fixApplicationModel(applicationID)
   194  	appModel.ApplicationTemplateID = nil
   195  	return appModel
   196  }
   197  
   198  func fixApplicationTemplateModel() *model.ApplicationTemplate {
   199  	return &model.ApplicationTemplate{
   200  		ID:                   ApplicationTemplateID,
   201  		Name:                 "application template",
   202  		Description:          str.Ptr("some very detailed description"),
   203  		ApplicationInputJSON: `{"name":"foo","providerName":"compass","description":"Lorem ipsum","labels":{"test":["val","val2"]},"healthCheckURL":"https://foo.bar","webhooks":[{"type":"","url":"webhook1.foo.bar","auth":null},{"type":"","url":"webhook2.foo.bar","auth":null}],"integrationSystemID":"iiiiiiiii-iiii-iiii-iiii-iiiiiiiiiiii"}`,
   204  	}
   205  }
   206  
   207  func unusedAppRepo() *automock.ApplicationRepository {
   208  	return &automock.ApplicationRepository{}
   209  }
   210  
   211  func unusedAppTemplateRepo() *automock.ApplicationTemplateRepository {
   212  	return &automock.ApplicationTemplateRepository{}
   213  }
   214  
   215  func unusedRuntimeRepo() *automock.RuntimeRepository {
   216  	return &automock.RuntimeRepository{}
   217  }
   218  
   219  func unusedRuntimeCtxRepo() *automock.RuntimeContextRepository {
   220  	return &automock.RuntimeContextRepository{}
   221  }
   222  
   223  func unusedLabelRepo() *automock.LabelRepository {
   224  	return &automock.LabelRepository{}
   225  }