github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/apptemplateversion/fixtures_test.go (about) 1 package apptemplateversion_test 2 3 import ( 4 "database/sql/driver" 5 "encoding/json" 6 "errors" 7 "testing" 8 "time" 9 10 "github.com/DATA-DOG/go-sqlmock" 11 "github.com/kyma-incubator/compass/components/director/internal/domain/apptemplateversion" 12 "github.com/kyma-incubator/compass/components/director/internal/model" 13 "github.com/kyma-incubator/compass/components/director/internal/repo" 14 "github.com/kyma-incubator/compass/components/director/pkg/str" 15 "github.com/stretchr/testify/require" 16 ) 17 18 const ( 19 appTemplateVersionID = "44444444-1111-2222-3333-51d5356e7e09" 20 testTitle = "testTitle" 21 appTemplateID = "58963c6f-24f6-4128-a05c-51d5356e7e09" 22 testVersion = "2306" 23 ) 24 25 var ( 26 mockedTimestamp = time.Now() 27 testCorrelationIDs = json.RawMessage(`["one"]`) 28 testError = errors.New("test error") 29 testTableColumns = []string{"id", "version", "title", "correlation_ids", "release_date", "created_at", "app_template_id"} 30 ) 31 32 func fixModelApplicationTemplateVersion(id string) *model.ApplicationTemplateVersion { 33 return &model.ApplicationTemplateVersion{ 34 ID: id, 35 Version: testVersion, 36 Title: str.Ptr(testTitle), 37 ReleaseDate: str.Ptr(mockedTimestamp.String()), 38 CorrelationIDs: testCorrelationIDs, 39 CreatedAt: mockedTimestamp, 40 ApplicationTemplateID: appTemplateID, 41 } 42 } 43 44 func fixModelApplicationTemplateVersionInput() *model.ApplicationTemplateVersionInput { 45 return &model.ApplicationTemplateVersionInput{ 46 Version: testVersion, 47 Title: str.Ptr(testTitle), 48 ReleaseDate: str.Ptr(mockedTimestamp.String()), 49 CorrelationIDs: testCorrelationIDs, 50 } 51 } 52 53 func fixEntityApplicationTemplateVersion(t *testing.T, id string) *apptemplateversion.Entity { 54 marshalledCorrelationIDs, err := json.Marshal(testCorrelationIDs) 55 require.NoError(t, err) 56 57 return &apptemplateversion.Entity{ 58 ID: id, 59 Version: testVersion, 60 Title: repo.NewNullableString(str.Ptr(testTitle)), 61 ReleaseDate: repo.NewValidNullableString(mockedTimestamp.String()), 62 CorrelationIDs: repo.NewValidNullableString(string(marshalledCorrelationIDs)), 63 CreatedAt: mockedTimestamp, 64 ApplicationTemplateID: appTemplateID, 65 } 66 } 67 68 func fixColumns() []string { 69 return []string{"id", "version", "title", "correlation_ids", "release_date", "created_at", "app_template_id"} 70 } 71 72 func fixAppTemplateVersionCreateArgs(entity apptemplateversion.Entity) []driver.Value { 73 return []driver.Value{entity.ID, entity.Version, entity.Title, entity.CorrelationIDs, entity.ReleaseDate, entity.CreatedAt, entity.ApplicationTemplateID} 74 } 75 76 func fixSQLRows(entities []apptemplateversion.Entity) *sqlmock.Rows { 77 out := sqlmock.NewRows(testTableColumns) 78 for _, entity := range entities { 79 out.AddRow(entity.ID, entity.Version, entity.Title, entity.CorrelationIDs, entity.ReleaseDate, entity.CreatedAt, entity.ApplicationTemplateID) 80 } 81 return out 82 }