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

     1  package label_test
     2  
     3  import (
     4  	"database/sql"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/internal/domain/label"
     7  	"github.com/kyma-incubator/compass/components/director/internal/model"
     8  	"github.com/kyma-incubator/compass/components/director/pkg/str"
     9  )
    10  
    11  const (
    12  	labelID  = "lblId"
    13  	refID    = "refID"
    14  	key      = "test"
    15  	value    = "test"
    16  	tenantID = "b91b59f7-2563-40b2-aba9-fef726037aa3"
    17  )
    18  
    19  var fixColumns = []string{"id", "tenant_id", "app_id", "runtime_id", "runtime_context_id", "app_template_id", "key", "value", "version"}
    20  
    21  func fixModelLabel(objectType model.LabelableObject) *model.Label {
    22  	return fixModelLabelWithID(labelID, key, objectType)
    23  }
    24  
    25  func fixModelLabelWithID(id, key string, objectType model.LabelableObject) *model.Label {
    26  	return fixModelLabelWithRefID(id, key, objectType, refID)
    27  }
    28  
    29  func fixModelLabelWithRefID(id, key string, objectType model.LabelableObject, refID string) *model.Label {
    30  	result := &model.Label{
    31  		ID:         id,
    32  		Key:        key,
    33  		Value:      value,
    34  		ObjectID:   refID,
    35  		ObjectType: objectType,
    36  		Version:    42,
    37  	}
    38  	if objectType == model.TenantLabelableObject {
    39  		result.Tenant = str.Ptr(tenantID)
    40  	}
    41  	return result
    42  }
    43  
    44  func fixEntityLabel(objectType model.LabelableObject) *label.Entity {
    45  	return fixEntityLabelWithID(labelID, key, objectType)
    46  }
    47  
    48  func fixEntityLabelWithID(id, key string, objectType model.LabelableObject) *label.Entity {
    49  	return fixEntityLabelWithRefID(id, key, objectType, refID)
    50  }
    51  
    52  func fixEntityLabelWithRefID(id, key string, objectType model.LabelableObject, refID string) *label.Entity {
    53  	var tenant sql.NullString
    54  	var appID sql.NullString
    55  	var runtimeCtxID sql.NullString
    56  	var runtimeID sql.NullString
    57  	var appTmplID sql.NullString
    58  	switch objectType {
    59  	case model.RuntimeContextLabelableObject:
    60  		runtimeCtxID = sql.NullString{String: refID, Valid: true}
    61  	case model.RuntimeLabelableObject:
    62  		runtimeID = sql.NullString{String: refID, Valid: true}
    63  	case model.ApplicationLabelableObject:
    64  		appID = sql.NullString{String: refID, Valid: true}
    65  	case model.TenantLabelableObject:
    66  		tenant = sql.NullString{String: tenantID, Valid: true}
    67  	case model.AppTemplateLabelableObject:
    68  		appTmplID = sql.NullString{String: refID, Valid: true}
    69  	}
    70  
    71  	return &label.Entity{
    72  		Key:              key,
    73  		Value:            value,
    74  		ID:               id,
    75  		TenantID:         tenant,
    76  		AppID:            appID,
    77  		AppTemplateID:    appTmplID,
    78  		RuntimeContextID: runtimeCtxID,
    79  		RuntimeID:        runtimeID,
    80  		Version:          42,
    81  	}
    82  }