github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/integrationsystem/fixtures_test.go (about) 1 package integrationsystem_test 2 3 import ( 4 "database/sql/driver" 5 "errors" 6 7 pkgmodel "github.com/kyma-incubator/compass/components/director/pkg/model" 8 9 "github.com/kyma-incubator/compass/components/director/pkg/pagination" 10 11 "github.com/DATA-DOG/go-sqlmock" 12 "github.com/kyma-incubator/compass/components/director/internal/domain/integrationsystem" 13 "github.com/kyma-incubator/compass/components/director/internal/model" 14 "github.com/kyma-incubator/compass/components/director/pkg/graphql" 15 ) 16 17 const ( 18 testTenant = "tnt" 19 testExternalTenant = "external-tnt" 20 testID = "foo" 21 testName = "bar" 22 testPageSize = 3 23 testCursor = "" 24 ) 25 26 var ( 27 testError = errors.New("test error") 28 testDescription = "bazz" 29 testTableColumns = []string{"id", "name", "description"} 30 ) 31 32 func fixModelIntegrationSystem(id, name string) *model.IntegrationSystem { 33 return &model.IntegrationSystem{ 34 ID: id, 35 Name: name, 36 Description: &testDescription, 37 } 38 } 39 40 func fixGQLIntegrationSystem(id, name string) *graphql.IntegrationSystem { 41 return &graphql.IntegrationSystem{ 42 ID: id, 43 Name: name, 44 Description: &testDescription, 45 } 46 } 47 48 func fixModelIntegrationSystemInput(name string) model.IntegrationSystemInput { 49 return model.IntegrationSystemInput{ 50 Name: name, 51 Description: &testDescription, 52 } 53 } 54 55 func fixGQLIntegrationSystemInput(name string) graphql.IntegrationSystemInput { 56 return graphql.IntegrationSystemInput{ 57 Name: name, 58 Description: &testDescription, 59 } 60 } 61 62 func fixEntityIntegrationSystem(id, name string) *integrationsystem.Entity { 63 return &integrationsystem.Entity{ 64 ID: id, 65 Name: name, 66 Description: &testDescription, 67 } 68 } 69 70 type sqlRow struct { 71 id string 72 name string 73 description *string 74 } 75 76 func fixSQLRows(rows []sqlRow) *sqlmock.Rows { 77 out := sqlmock.NewRows(testTableColumns) 78 for _, row := range rows { 79 out.AddRow(row.id, row.name, row.description) 80 } 81 return out 82 } 83 84 func fixIntegrationSystemCreateArgs(ent integrationsystem.Entity) []driver.Value { 85 return []driver.Value{ent.ID, ent.Name, ent.Description} 86 } 87 88 func fixModelIntegrationSystemPage(intSystems []*model.IntegrationSystem) model.IntegrationSystemPage { 89 return model.IntegrationSystemPage{ 90 Data: intSystems, 91 PageInfo: &pagination.Page{ 92 StartCursor: "start", 93 EndCursor: "end", 94 HasNextPage: false, 95 }, 96 TotalCount: len(intSystems), 97 } 98 } 99 100 func fixGQLIntegrationSystemPage(intSystems []*graphql.IntegrationSystem) graphql.IntegrationSystemPage { 101 return graphql.IntegrationSystemPage{ 102 Data: intSystems, 103 PageInfo: &graphql.PageInfo{ 104 StartCursor: "start", 105 EndCursor: "end", 106 HasNextPage: false, 107 }, 108 TotalCount: len(intSystems), 109 } 110 } 111 112 func fixModelAuth() *model.Auth { 113 return &model.Auth{ 114 Credential: model.CredentialData{ 115 Basic: &model.BasicCredentialData{ 116 Username: "foo", 117 Password: "bar", 118 }, 119 }, 120 AdditionalHeaders: map[string][]string{"test": {"foo", "bar"}}, 121 AdditionalQueryParams: map[string][]string{"test": {"foo", "bar"}}, 122 RequestAuth: &model.CredentialRequestAuth{ 123 Csrf: &model.CSRFTokenCredentialRequestAuth{ 124 TokenEndpointURL: "foo.url", 125 Credential: model.CredentialData{ 126 Basic: &model.BasicCredentialData{ 127 Username: "boo", 128 Password: "far", 129 }, 130 }, 131 AdditionalHeaders: map[string][]string{"test": {"foo", "bar"}}, 132 AdditionalQueryParams: map[string][]string{"test": {"foo", "bar"}}, 133 }, 134 }, 135 } 136 } 137 138 func fixGQLAuth() *graphql.Auth { 139 return &graphql.Auth{ 140 Credential: &graphql.BasicCredentialData{ 141 Username: "foo", 142 Password: "bar", 143 }, 144 AdditionalHeaders: graphql.HTTPHeaders{"test": {"foo", "bar"}}, 145 AdditionalQueryParams: graphql.QueryParams{"test": {"foo", "bar"}}, 146 RequestAuth: &graphql.CredentialRequestAuth{ 147 Csrf: &graphql.CSRFTokenCredentialRequestAuth{ 148 TokenEndpointURL: "foo.url", 149 Credential: &graphql.BasicCredentialData{ 150 Username: "boo", 151 Password: "far", 152 }, 153 AdditionalHeaders: graphql.HTTPHeaders{"test": {"foo", "bar"}}, 154 AdditionalQueryParams: graphql.QueryParams{"test": {"foo", "bar"}}, 155 }, 156 }, 157 } 158 } 159 160 func fixModelSystemAuth(id, intSysID string, auth *model.Auth) pkgmodel.SystemAuth { 161 return pkgmodel.SystemAuth{ 162 ID: id, 163 TenantID: nil, 164 IntegrationSystemID: &intSysID, 165 Value: auth, 166 } 167 } 168 169 func fixGQLSystemAuth(id string, auth *graphql.Auth) *graphql.IntSysSystemAuth { 170 return &graphql.IntSysSystemAuth{ 171 ID: id, 172 Auth: auth, 173 } 174 }