Skip to content

Commit

Permalink
Fixes 4821: expose URL on snapshot/for_date (#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsherrill authored Oct 9, 2024
1 parent c2b23d2 commit 30370c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 7 additions & 3 deletions pkg/dao/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ func (sDao *snapshotDaoImpl) FetchSnapshotsByDateAndRepository(ctx context.Conte
return api.ListSnapshotByDateResponse{}, err
}

pulpContentPath, err := sDao.pulpClient.GetContentPath(ctx)
if err != nil {
return api.ListSnapshotByDateResponse{}, err
}

repoUUIDCount := len(request.RepositoryUUIDS)
listResponse := make([]api.SnapshotForDate, repoUUIDCount)

Expand All @@ -400,9 +405,8 @@ func (sDao *snapshotDaoImpl) FetchSnapshotsByDateAndRepository(ctx context.Conte
})

if indx != -1 {
apiResponse := api.SnapshotResponse{}
snapshotModelToApi(snaps[indx], &apiResponse)
listResponse[i].Match = &apiResponse
apiResponse := snapshotConvertToResponses([]models.Snapshot{snaps[indx]}, pulpContentPath)
listResponse[i].Match = &apiResponse[0]
}

listResponse[i].IsAfter = indx != -1 && snaps[indx].Base.CreatedAt.After(date)
Expand Down
17 changes: 11 additions & 6 deletions pkg/dao/snapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,16 @@ func (s *SnapshotsSuite) TestFetchSnapshotsByDateAndRepository() {
t := s.T()
tx := s.tx

mockPulpClient := pulp_client.NewMockPulpClient(t)
sDao := snapshotDaoImpl{db: tx, pulpClient: mockPulpClient}
mockPulpClient.On("GetContentPath", context.Background()).Return(testContentPath, nil)

repoConfig := s.createRepository()
baseTime := time.Now()
s.createSnapshotAtSpecifiedTime(repoConfig, baseTime.Add(-time.Hour*30)) // Before Date
second := s.createSnapshotAtSpecifiedTime(repoConfig, baseTime) // Target Date
s.createSnapshotAtSpecifiedTime(repoConfig, baseTime.Add(time.Hour*30)) // After Date

sDao := GetSnapshotDao(tx)

request := api.ListSnapshotByDateRequest{}

request.Date = api.Date(second.Base.CreatedAt)
Expand All @@ -491,12 +493,17 @@ func (s *SnapshotsSuite) TestFetchSnapshotsByDateAndRepository() {
assert.Equal(t, false, response.Data[0].IsAfter)
assert.Equal(t, second.Base.UUID, response.Data[0].Match.UUID)
assert.Equal(t, second.Base.CreatedAt.Day(), response.Data[0].Match.CreatedAt.Day())
assert.NotEmpty(t, response.Data[0].Match.URL)
}

func (s *SnapshotsSuite) TestFetchSnapshotsByDateAndRepositoryMulti() {
t := s.T()
tx := s.tx

mockPulpClient := pulp_client.NewMockPulpClient(t)
sDao := snapshotDaoImpl{db: tx, pulpClient: mockPulpClient}
mockPulpClient.On("GetContentPath", context.Background()).Return(testContentPath, nil)

repoConfig := s.createRepository()
repoConfig2 := s.createRepository()
redhatRepo := s.createRedhatRepository()
Expand Down Expand Up @@ -527,8 +534,6 @@ func (s *SnapshotsSuite) TestFetchSnapshotsByDateAndRepositoryMulti() {
randomUUID.String(),
}

sDao := GetSnapshotDao(tx)

fullRepsonse, err := sDao.FetchSnapshotsByDateAndRepository(context.Background(), repoConfig.OrgID, request)
response := fullRepsonse.Data
assert.NoError(t, err)
Expand Down Expand Up @@ -595,14 +600,14 @@ func (s *SnapshotsSuite) TestListByTemplate() {
assert.Equal(t, 2, len(snapshots.Data))
assert.Equal(t, int64(2), totalSnapshots)

//// target 1
// target 1
assert.True(t, snapshots.Data[0].CreatedAt.After(t1b.CreatedAt))
assert.True(t, snapshots.Data[0].CreatedAt.Before(t1a.CreatedAt))
assert.True(t, bytes.Contains([]byte(snapshots.Data[0].RepositoryName), []byte("Last")))
assert.Equal(t, t1.Base.CreatedAt.Day(), snapshots.Data[0].CreatedAt.Day())
assert.Equal(t, repoConfig.UUID, snapshots.Data[0].RepositoryUUID)

//// target 2
// target 2
assert.True(t, snapshots.Data[1].CreatedAt.Before(t2a.CreatedAt))
assert.True(t, snapshots.Data[1].CreatedAt.Before(t2aa.CreatedAt))
assert.True(t, bytes.Contains([]byte(snapshots.Data[1].RepositoryName), []byte("First")))
Expand Down

0 comments on commit 30370c9

Please sign in to comment.