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

     1  package ordpackage_test
     2  
     3  import (
     4  	"database/sql"
     5  	"database/sql/driver"
     6  	"encoding/json"
     7  
     8  	"github.com/kyma-incubator/compass/components/director/pkg/str"
     9  
    10  	"github.com/kyma-incubator/compass/components/director/internal/repo"
    11  
    12  	ordpackage "github.com/kyma-incubator/compass/components/director/internal/domain/package"
    13  	"github.com/kyma-incubator/compass/components/director/internal/model"
    14  )
    15  
    16  const (
    17  	packageID        = "packageID"
    18  	tenantID         = "b91b59f7-2563-40b2-aba9-fef726037aa3"
    19  	ordID            = "com.compass.v1"
    20  	externalTenantID = "externalTenantID"
    21  	resourceHash     = "123456"
    22  )
    23  
    24  var (
    25  	appID                = "appID"
    26  	appTemplateVersionID = "appTemplateVersionID"
    27  )
    28  
    29  func fixEntityPackageForApp() *ordpackage.Entity {
    30  	return fixEntityPackageWithTitleForApp("title")
    31  }
    32  
    33  func fixEntityPackageForAppTemplateVersion() *ordpackage.Entity {
    34  	return fixEntityPackageWithTitleForAppTemplateVersion("title")
    35  }
    36  
    37  func fixEntityPackageWithTitleForApp(title string) *ordpackage.Entity {
    38  	entity := fixEntityPackageWithTitle(title)
    39  	entity.ApplicationID = repo.NewValidNullableString(appID)
    40  	return entity
    41  }
    42  
    43  func fixEntityPackageWithTitleForAppTemplateVersion(title string) *ordpackage.Entity {
    44  	entity := fixEntityPackageWithTitle(title)
    45  	entity.ApplicationTemplateVersionID = repo.NewValidNullableString(appTemplateVersionID)
    46  	return entity
    47  }
    48  
    49  func fixEntityPackageWithTitle(title string) *ordpackage.Entity {
    50  	return &ordpackage.Entity{
    51  		ID:                  packageID,
    52  		OrdID:               ordID,
    53  		Vendor:              sql.NullString{String: "vendorID", Valid: true},
    54  		Title:               title,
    55  		ShortDescription:    "short desc",
    56  		Description:         "desc",
    57  		Version:             "v1.0.5",
    58  		PackageLinks:        repo.NewValidNullableString("{}"),
    59  		Links:               repo.NewValidNullableString("[]"),
    60  		LicenseType:         sql.NullString{String: "test", Valid: true},
    61  		SupportInfo:         sql.NullString{String: "support-info", Valid: true},
    62  		Tags:                repo.NewValidNullableString("[]"),
    63  		Countries:           repo.NewValidNullableString("[]"),
    64  		Labels:              repo.NewValidNullableString("{}"),
    65  		PolicyLevel:         "test",
    66  		CustomPolicyLevel:   sql.NullString{},
    67  		PartOfProducts:      repo.NewValidNullableString("[\"test\"]"),
    68  		LineOfBusiness:      repo.NewValidNullableString("[]"),
    69  		Industry:            repo.NewValidNullableString("[]"),
    70  		ResourceHash:        repo.NewValidNullableString(resourceHash),
    71  		DocumentationLabels: repo.NewValidNullableString("[]"),
    72  	}
    73  }
    74  
    75  func fixNilModelPackage() *model.Package {
    76  	return nil
    77  }
    78  
    79  func fixPackageModelForApp() *model.Package {
    80  	return fixPackageModelWithTitleForApp("title")
    81  }
    82  
    83  func fixPackageModelForAppTemplateVersion() *model.Package {
    84  	return fixPackageModelWithTitleForAppTemplateVersion("title")
    85  }
    86  
    87  func fixPackageModelWithTitleForAppTemplateVersion(title string) *model.Package {
    88  	pkg := fixPackageModelWithTitle(title)
    89  	pkg.ApplicationTemplateVersionID = &appTemplateVersionID
    90  	return pkg
    91  }
    92  func fixPackageModelWithTitleForApp(title string) *model.Package {
    93  	pkg := fixPackageModelWithTitle(title)
    94  	pkg.ApplicationID = &appID
    95  	return pkg
    96  }
    97  
    98  func fixPackageModelWithTitle(title string) *model.Package {
    99  	vendorID := "vendorID"
   100  	licenceType := "test"
   101  	supportInfo := "support-info"
   102  	return &model.Package{
   103  		ID:                  packageID,
   104  		OrdID:               ordID,
   105  		Vendor:              &vendorID,
   106  		Title:               title,
   107  		ShortDescription:    "short desc",
   108  		Description:         "desc",
   109  		Version:             "v1.0.5",
   110  		PackageLinks:        json.RawMessage("{}"),
   111  		Links:               json.RawMessage("[]"),
   112  		LicenseType:         &licenceType,
   113  		SupportInfo:         &supportInfo,
   114  		Tags:                json.RawMessage("[]"),
   115  		Countries:           json.RawMessage("[]"),
   116  		Labels:              json.RawMessage("{}"),
   117  		PolicyLevel:         "test",
   118  		CustomPolicyLevel:   nil,
   119  		PartOfProducts:      json.RawMessage("[\"test\"]"),
   120  		LineOfBusiness:      json.RawMessage("[]"),
   121  		Industry:            json.RawMessage("[]"),
   122  		ResourceHash:        str.Ptr(resourceHash),
   123  		DocumentationLabels: json.RawMessage("[]"),
   124  	}
   125  }
   126  
   127  func fixPackageModelInput() *model.PackageInput {
   128  	vendorID := "vendorID"
   129  	licenceType := "test"
   130  	supportInfo := "support-info"
   131  	return &model.PackageInput{
   132  		OrdID:               ordID,
   133  		Vendor:              &vendorID,
   134  		Title:               "title",
   135  		ShortDescription:    "short desc",
   136  		Description:         "desc",
   137  		Version:             "v1.0.5",
   138  		PackageLinks:        json.RawMessage("{}"),
   139  		Links:               json.RawMessage("[]"),
   140  		LicenseType:         &licenceType,
   141  		SupportInfo:         &supportInfo,
   142  		Tags:                json.RawMessage("[]"),
   143  		Countries:           json.RawMessage("[]"),
   144  		Labels:              json.RawMessage("{}"),
   145  		PolicyLevel:         "test",
   146  		CustomPolicyLevel:   nil,
   147  		PartOfProducts:      json.RawMessage("[\"test\"]"),
   148  		LineOfBusiness:      json.RawMessage("[]"),
   149  		Industry:            json.RawMessage("[]"),
   150  		DocumentationLabels: json.RawMessage("[]"),
   151  	}
   152  }
   153  
   154  func fixPackageColumns() []string {
   155  	return []string{"id", "app_id", "app_template_version_id", "ord_id", "vendor", "title", "short_description",
   156  		"description", "version", "package_links", "links", "licence_type", "tags", "countries", "labels", "policy_level",
   157  		"custom_policy_level", "part_of_products", "line_of_business", "industry", "resource_hash", "documentation_labels", "support_info"}
   158  }
   159  
   160  func fixPackageRowForApp() []driver.Value {
   161  	return fixPackageRowWithTitleForApp("title")
   162  }
   163  
   164  func fixPackageRowForAppTemplateVersion() []driver.Value {
   165  	return fixPackageRowWithTitleForAppTemplateVersion("title")
   166  }
   167  
   168  func fixPackageRowWithTitleForApp(title string) []driver.Value {
   169  	return []driver.Value{packageID, appID, repo.NewValidNullableString(""), ordID, "vendorID", title, "short desc", "desc", "v1.0.5",
   170  		repo.NewValidNullableString("{}"), repo.NewValidNullableString("[]"), "test", repo.NewValidNullableString("[]"), repo.NewValidNullableString("[]"), repo.NewValidNullableString("{}"),
   171  		"test", nil, repo.NewValidNullableString("[\"test\"]"), repo.NewValidNullableString("[]"), repo.NewValidNullableString("[]"), repo.NewValidNullableString(resourceHash), repo.NewValidNullableString("[]"), "support-info"}
   172  }
   173  
   174  func fixPackageRowWithTitleForAppTemplateVersion(title string) []driver.Value {
   175  	return []driver.Value{packageID, repo.NewValidNullableString(""), appTemplateVersionID, ordID, "vendorID", title, "short desc", "desc", "v1.0.5",
   176  		repo.NewValidNullableString("{}"), repo.NewValidNullableString("[]"), "test", repo.NewValidNullableString("[]"), repo.NewValidNullableString("[]"), repo.NewValidNullableString("{}"),
   177  		"test", nil, repo.NewValidNullableString("[\"test\"]"), repo.NewValidNullableString("[]"), repo.NewValidNullableString("[]"), repo.NewValidNullableString(resourceHash), repo.NewValidNullableString("[]"), "support-info"}
   178  }
   179  
   180  func fixPackageUpdateArgs() []driver.Value {
   181  	return []driver.Value{"vendorID", "title", "short desc", "desc", "v1.0.5", repo.NewValidNullableString("{}"), repo.NewValidNullableString("[]"),
   182  		"test", repo.NewValidNullableString("[]"), repo.NewValidNullableString("[]"), repo.NewValidNullableString("{}"), "test", nil, repo.NewValidNullableString("[\"test\"]"),
   183  		repo.NewValidNullableString("[]"), repo.NewValidNullableString("[]"), repo.NewValidNullableString(resourceHash), repo.NewValidNullableString("[]"), "support-info"}
   184  }