@@ -81,6 +81,7 @@ func (s *TemplateSuite) TestCreateDeleteCreateSameName() {
81
81
Version : pointy .String (config .El8 ),
82
82
Date : & timeNow ,
83
83
OrgID : & orgID ,
84
+ User : pointy .String ("user" ),
84
85
}
85
86
86
87
respTemplate , err := templateDao .Create (context .Background (), reqTemplate )
@@ -105,6 +106,8 @@ func (s *TemplateSuite) TestCreateDeleteCreateSameName() {
105
106
assert .Equal (s .T (), * reqTemplate .Arch , respTemplate .Arch )
106
107
assert .Equal (s .T (), * reqTemplate .Version , respTemplate .Version )
107
108
assert .Len (s .T (), reqTemplate .RepositoryUUIDS , 2 )
109
+ assert .Equal (s .T (), * reqTemplate .User , respTemplate .CreatedBy )
110
+ assert .Equal (s .T (), * reqTemplate .User , respTemplate .LastUpdatedBy )
108
111
}
109
112
110
113
func (s * TemplateSuite ) TestFetch () {
@@ -122,6 +125,10 @@ func (s *TemplateSuite) TestFetch() {
122
125
assert .Equal (s .T (), found .Name , resp .Name )
123
126
assert .Equal (s .T (), found .OrgID , resp .OrgID )
124
127
assert .Equal (s .T (), candlepin_client .GetEnvironmentID (resp .UUID ), resp .RHSMEnvironmentID )
128
+ assert .Equal (s .T (), found .LastUpdatedBy , resp .LastUpdatedBy )
129
+ assert .Equal (s .T (), found .CreatedBy , resp .CreatedBy )
130
+ assert .Equal (s .T (), found .CreatedAt , resp .CreatedAt )
131
+ assert .Equal (s .T (), found .UpdatedAt , resp .UpdatedAt )
125
132
}
126
133
127
134
func (s * TemplateSuite ) TestFetchNotFound () {
@@ -151,18 +158,22 @@ func (s *TemplateSuite) TestList() {
151
158
var found []models.Template
152
159
var total int64
153
160
154
- s .seedWithRepoConfig (orgIDTest )
161
+ s .seedWithRepoConfig (orgIDTest , 1 )
155
162
156
163
err = s .tx .Where ("org_id = ?" , orgIDTest ).Find (& found ).Count (& total ).Error
157
164
assert .NoError (s .T (), err )
158
- assert .Equal (s .T (), int64 (2 ), total )
165
+ assert .Equal (s .T (), int64 (1 ), total )
159
166
160
167
responses , total , err := templateDao .List (context .Background (), orgIDTest , api.PaginationData {Limit : - 1 }, api.TemplateFilterData {})
161
168
assert .NoError (s .T (), err )
162
- assert .Equal (s .T (), int64 (2 ), total )
163
- assert .Len (s .T (), responses .Data , 2 )
169
+ assert .Equal (s .T (), int64 (1 ), total )
170
+ assert .Len (s .T (), responses .Data , 1 )
164
171
assert .Len (s .T (), responses .Data [0 ].RepositoryUUIDS , 2 )
165
172
assert .Equal (s .T (), candlepin_client .GetEnvironmentID (responses .Data [0 ].UUID ), responses .Data [0 ].RHSMEnvironmentID )
173
+ assert .Equal (s .T (), responses .Data [0 ].CreatedBy , found [0 ].CreatedBy )
174
+ assert .Equal (s .T (), responses .Data [0 ].LastUpdatedBy , found [0 ].LastUpdatedBy )
175
+ assert .Equal (s .T (), responses .Data [0 ].CreatedAt , found [0 ].CreatedAt )
176
+ assert .Equal (s .T (), responses .Data [0 ].UpdatedAt , found [0 ].UpdatedAt )
166
177
}
167
178
168
179
func (s * TemplateSuite ) TestListNoTemplates () {
@@ -253,7 +264,7 @@ func (s *TemplateSuite) TestListFilters() {
253
264
assert .Equal (s .T (), found [0 ].Arch , responses .Data [0 ].Arch )
254
265
255
266
// Test Filter by RepositoryUUIDs
256
- template , rcUUIDs := s .seedWithRepoConfig (orgIDTest )
267
+ template , rcUUIDs := s .seedWithRepoConfig (orgIDTest , 2 )
257
268
filterData = api.TemplateFilterData {RepositoryUUIDs : []string {rcUUIDs [0 ]}}
258
269
responses , total , err = templateDao .List (context .Background (), orgIDTest , api.PaginationData {Limit : - 1 }, filterData )
259
270
assert .NoError (s .T (), err )
@@ -390,22 +401,22 @@ func (s *TemplateSuite) fetchTemplate(uuid string) models.Template {
390
401
return found
391
402
}
392
403
393
- func (s * TemplateSuite ) seedWithRepoConfig (orgId string ) (models.Template , []string ) {
404
+ func (s * TemplateSuite ) seedWithRepoConfig (orgId string , templateSize int ) (models.Template , []string ) {
394
405
err := seeds .SeedRepositoryConfigurations (s .tx , 2 , seeds.SeedOptions {OrgID : orgId })
395
406
require .NoError (s .T (), err )
396
407
397
408
var rcUUIDs []string
398
409
err = s .tx .Model (models.RepositoryConfiguration {}).Where ("org_id = ?" , orgIDTest ).Select ("uuid" ).Find (& rcUUIDs ).Error
399
410
require .NoError (s .T (), err )
400
411
401
- templates , err := seeds .SeedTemplates (s .tx , 2 , seeds.TemplateSeedOptions {OrgID : orgId , RepositoryConfigUUIDs : rcUUIDs })
412
+ templates , err := seeds .SeedTemplates (s .tx , templateSize , seeds.TemplateSeedOptions {OrgID : orgId , RepositoryConfigUUIDs : rcUUIDs })
402
413
require .NoError (s .T (), err )
403
414
404
415
return templates [0 ], rcUUIDs
405
416
}
406
417
407
418
func (s * TemplateSuite ) TestUpdate () {
408
- origTempl , rcUUIDs := s .seedWithRepoConfig (orgIDTest )
419
+ origTempl , rcUUIDs := s .seedWithRepoConfig (orgIDTest , 2 )
409
420
410
421
templateDao := templateDaoImpl {db : s .tx }
411
422
_ , err := templateDao .Update (context .Background (), orgIDTest , origTempl .UUID , api.TemplateUpdateRequest {Description : pointy .Pointer ("scratch" ), RepositoryUUIDS : []string {rcUUIDs [0 ]}})
@@ -424,6 +435,11 @@ func (s *TemplateSuite) TestUpdate() {
424
435
425
436
_ , err = templateDao .Update (context .Background (), orgIDTest , found .UUID , api.TemplateUpdateRequest {RepositoryUUIDS : []string {"Notarealrepouuid" }})
426
437
assert .Error (s .T (), err )
438
+
439
+ _ , err = templateDao .Update (context .Background (), orgIDTest , found .UUID , api.TemplateUpdateRequest {RepositoryUUIDS : []string {rcUUIDs [1 ]}, User : pointy .Pointer ("new user" )})
440
+ require .NoError (s .T (), err )
441
+ found = s .fetchTemplate (origTempl .UUID )
442
+ assert .Equal (s .T (), "new user" , found .LastUpdatedBy )
427
443
}
428
444
429
445
func (s * TemplateSuite ) TestGetRepoChanges () {
0 commit comments