Skip to content

Commit

Permalink
PMM-12899 rename BackupsService to BackupService
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Apr 4, 2024
1 parent 12d6aaa commit 64792d5
Show file tree
Hide file tree
Showing 32 changed files with 1,007 additions and 1,008 deletions.
130 changes: 65 additions & 65 deletions api-tests/backup/backups_test.go → api-tests/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
pmmapitests "github.com/percona/pmm/api-tests"
"github.com/percona/pmm/api-tests/management"
backupClient "github.com/percona/pmm/api/backup/v1/json/client"
backups "github.com/percona/pmm/api/backup/v1/json/client/backups_service"
backup "github.com/percona/pmm/api/backup/v1/json/client/backup_service"
locations "github.com/percona/pmm/api/backup/v1/json/client/locations_service"
managementClient "github.com/percona/pmm/api/management/v1/json/client"
mservice "github.com/percona/pmm/api/management/v1/json/client/management_service"
Expand Down Expand Up @@ -104,17 +104,17 @@ func TestScheduleBackup(t *testing.T) {
defer deleteLocation(t, backupClient.Default.LocationsService, locationID)

t.Run("schedule logical backup", func(t *testing.T) {
client := backupClient.Default.BackupsService
backupRes, err := client.ScheduleBackup(&backups.ScheduleBackupParams{
Body: backups.ScheduleBackupBody{
client := backupClient.Default.BackupService
backupRes, err := client.ScheduleBackup(&backup.ScheduleBackupParams{
Body: backup.ScheduleBackupBody{
ServiceID: mongo1ID,
LocationID: locationID,
CronExpression: "0 1 1 1 1",
Name: "testing",
Description: "testing",
Mode: pointer.ToString(backups.ScheduleBackupBodyModeBACKUPMODESNAPSHOT),
Mode: pointer.ToString(backup.ScheduleBackupBodyModeBACKUPMODESNAPSHOT),
Enabled: false,
DataModel: pointer.ToString(backups.StartBackupBodyDataModelDATAMODELLOGICAL),
DataModel: pointer.ToString(backup.StartBackupBodyDataModelDATAMODELLOGICAL),
Folder: "backup_folder",
},
Context: pmmapitests.Context,
Expand All @@ -123,58 +123,58 @@ func TestScheduleBackup(t *testing.T) {
require.NoError(t, err)
assert.NotEmpty(t, backupRes.Payload.ScheduledBackupID)

body := backups.ChangeScheduledBackupBody{
body := backup.ChangeScheduledBackupBody{
ScheduledBackupID: backupRes.Payload.ScheduledBackupID,
Enabled: pointer.ToBool(true),
CronExpression: pointer.ToString("0 2 2 2 2"),
Name: pointer.ToString("test2"),
Description: pointer.ToString("test2"),
}
changeRes, err := client.ChangeScheduledBackup(&backups.ChangeScheduledBackupParams{
changeRes, err := client.ChangeScheduledBackup(&backup.ChangeScheduledBackupParams{
Body: body,
Context: pmmapitests.Context,
})
require.NoError(t, err)
assert.NotEmpty(t, changeRes)

listRes, err := client.ListScheduledBackups(&backups.ListScheduledBackupsParams{
listRes, err := client.ListScheduledBackups(&backup.ListScheduledBackupsParams{
Context: pmmapitests.Context,
})
require.NoError(t, err)

var backup *backups.ListScheduledBackupsOKBodyScheduledBackupsItems0
var bkp *backup.ListScheduledBackupsOKBodyScheduledBackupsItems0
for _, b := range listRes.Payload.ScheduledBackups {
if b.ScheduledBackupID == backupRes.Payload.ScheduledBackupID {
backup = b
bkp = b
break
}
}
require.NotNil(t, backup)
require.NotNil(t, bkp)

// Assert change
assert.Equal(t, pointer.GetBool(body.Enabled), backup.Enabled)
assert.Equal(t, pointer.GetString(body.Name), backup.Name)
assert.Equal(t, pointer.GetString(body.Description), backup.Description)
assert.Equal(t, pointer.GetString(body.CronExpression), backup.CronExpression)
assert.Equal(t, "backup_folder", backup.Folder)

_, err = client.RemoveScheduledBackup(&backups.RemoveScheduledBackupParams{
Body: backups.RemoveScheduledBackupBody{
assert.Equal(t, pointer.GetBool(body.Enabled), bkp.Enabled)
assert.Equal(t, pointer.GetString(body.Name), bkp.Name)
assert.Equal(t, pointer.GetString(body.Description), bkp.Description)
assert.Equal(t, pointer.GetString(body.CronExpression), bkp.CronExpression)
assert.Equal(t, "backup_folder", bkp.Folder)

_, err = client.RemoveScheduledBackup(&backup.RemoveScheduledBackupParams{
Body: backup.RemoveScheduledBackupBody{
ScheduledBackupID: backupRes.Payload.ScheduledBackupID,
},
Context: pmmapitests.Context,
})
require.NoError(t, err)

find := func(id string, backups []*backups.ListScheduledBackupsOKBodyScheduledBackupsItems0) *backups.ListScheduledBackupsOKBodyScheduledBackupsItems0 {
find := func(id string, backups []*backup.ListScheduledBackupsOKBodyScheduledBackupsItems0) *backup.ListScheduledBackupsOKBodyScheduledBackupsItems0 {
for _, b := range backups {
if b.ScheduledBackupID == id {
return b
}
}
return nil
}
listRes, err = client.ListScheduledBackups(&backups.ListScheduledBackupsParams{
listRes, err = client.ListScheduledBackups(&backup.ListScheduledBackupsParams{
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand All @@ -185,34 +185,34 @@ func TestScheduleBackup(t *testing.T) {
})

t.Run("create multiple snapshot backups", func(t *testing.T) {
client := backupClient.Default.BackupsService
sb1, err := client.ScheduleBackup(&backups.ScheduleBackupParams{
Body: backups.ScheduleBackupBody{
client := backupClient.Default.BackupService
sb1, err := client.ScheduleBackup(&backup.ScheduleBackupParams{
Body: backup.ScheduleBackupBody{
ServiceID: mongo1ID,
LocationID: locationID,
CronExpression: "0 1 1 1 1",
Name: "testing1",
Description: "testing",
Mode: pointer.ToString(backups.ScheduleBackupBodyModeBACKUPMODESNAPSHOT),
Mode: pointer.ToString(backup.ScheduleBackupBodyModeBACKUPMODESNAPSHOT),
Enabled: true,
DataModel: pointer.ToString(backups.StartBackupBodyDataModelDATAMODELLOGICAL),
DataModel: pointer.ToString(backup.StartBackupBodyDataModelDATAMODELLOGICAL),
},
Context: pmmapitests.Context,
})

require.NoError(t, err)
defer removeScheduledBackup(t, sb1.Payload.ScheduledBackupID)

sb2, err := client.ScheduleBackup(&backups.ScheduleBackupParams{
Body: backups.ScheduleBackupBody{
sb2, err := client.ScheduleBackup(&backup.ScheduleBackupParams{
Body: backup.ScheduleBackupBody{
ServiceID: mongo1ID,
LocationID: locationID,
CronExpression: "0 1 1 1 1",
Name: "testing2",
Description: "testing",
Mode: pointer.ToString(backups.ScheduleBackupBodyModeBACKUPMODESNAPSHOT),
Mode: pointer.ToString(backup.ScheduleBackupBodyModeBACKUPMODESNAPSHOT),
Enabled: true,
DataModel: pointer.ToString(backups.StartBackupBodyDataModelDATAMODELLOGICAL),
DataModel: pointer.ToString(backup.StartBackupBodyDataModelDATAMODELLOGICAL),
},
Context: pmmapitests.Context,
})
Expand All @@ -222,52 +222,52 @@ func TestScheduleBackup(t *testing.T) {
})

t.Run("create PITR backup when other backups disabled", func(t *testing.T) {
client := backupClient.Default.BackupsService
client := backupClient.Default.BackupService

sb1, err := client.ScheduleBackup(&backups.ScheduleBackupParams{
Body: backups.ScheduleBackupBody{
sb1, err := client.ScheduleBackup(&backup.ScheduleBackupParams{
Body: backup.ScheduleBackupBody{
ServiceID: mongo1ID,
LocationID: locationID,
CronExpression: "0 1 1 1 1",
Name: "testing1",
Description: "testing",
Mode: pointer.ToString(backups.ScheduleBackupBodyModeBACKUPMODESNAPSHOT),
Mode: pointer.ToString(backup.ScheduleBackupBodyModeBACKUPMODESNAPSHOT),
Enabled: false,
DataModel: pointer.ToString(backups.StartBackupBodyDataModelDATAMODELLOGICAL),
DataModel: pointer.ToString(backup.StartBackupBodyDataModelDATAMODELLOGICAL),
},
Context: pmmapitests.Context,
})

require.NoError(t, err)
defer removeScheduledBackup(t, sb1.Payload.ScheduledBackupID)

pitrb1, err := client.ScheduleBackup(&backups.ScheduleBackupParams{
Body: backups.ScheduleBackupBody{
pitrb1, err := client.ScheduleBackup(&backup.ScheduleBackupParams{
Body: backup.ScheduleBackupBody{
ServiceID: mongo1ID,
LocationID: locationID,
CronExpression: "0 1 1 1 1",
Name: "testing2",
Description: "testing",
Mode: pointer.ToString(backups.ScheduleBackupBodyModeBACKUPMODEPITR),
Mode: pointer.ToString(backup.ScheduleBackupBodyModeBACKUPMODEPITR),
Enabled: false,
DataModel: pointer.ToString(backups.StartBackupBodyDataModelDATAMODELLOGICAL),
DataModel: pointer.ToString(backup.StartBackupBodyDataModelDATAMODELLOGICAL),
},
Context: pmmapitests.Context,
})

require.NoError(t, err)
defer removeScheduledBackup(t, pitrb1.Payload.ScheduledBackupID)

pitrb2, err := client.ScheduleBackup(&backups.ScheduleBackupParams{
Body: backups.ScheduleBackupBody{
pitrb2, err := client.ScheduleBackup(&backup.ScheduleBackupParams{
Body: backup.ScheduleBackupBody{
ServiceID: mongo1ID,
LocationID: locationID,
CronExpression: "0 1 1 1 1",
Name: "testing3",
Description: "testing",
Mode: pointer.ToString(backups.ScheduleBackupBodyModeBACKUPMODEPITR),
Mode: pointer.ToString(backup.ScheduleBackupBodyModeBACKUPMODEPITR),
Enabled: true,
DataModel: pointer.ToString(backups.StartBackupBodyDataModelDATAMODELLOGICAL),
DataModel: pointer.ToString(backup.StartBackupBodyDataModelDATAMODELLOGICAL),
},
Context: pmmapitests.Context,
})
Expand All @@ -277,34 +277,34 @@ func TestScheduleBackup(t *testing.T) {
})

t.Run("only one enabled PITR backup allowed for the same cluster", func(t *testing.T) {
client := backupClient.Default.BackupsService
sb1, err := client.ScheduleBackup(&backups.ScheduleBackupParams{
Body: backups.ScheduleBackupBody{
client := backupClient.Default.BackupService
sb1, err := client.ScheduleBackup(&backup.ScheduleBackupParams{
Body: backup.ScheduleBackupBody{
ServiceID: mongo1ID,
LocationID: locationID,
CronExpression: "0 1 1 1 1",
Name: "testing1",
Description: "testing",
Mode: pointer.ToString(backups.ScheduleBackupBodyModeBACKUPMODEPITR),
Mode: pointer.ToString(backup.ScheduleBackupBodyModeBACKUPMODEPITR),
Enabled: true,
DataModel: pointer.ToString(backups.StartBackupBodyDataModelDATAMODELLOGICAL),
DataModel: pointer.ToString(backup.StartBackupBodyDataModelDATAMODELLOGICAL),
},
Context: pmmapitests.Context,
})

require.NoError(t, err)
defer removeScheduledBackup(t, sb1.Payload.ScheduledBackupID)

_, err = client.ScheduleBackup(&backups.ScheduleBackupParams{
Body: backups.ScheduleBackupBody{
_, err = client.ScheduleBackup(&backup.ScheduleBackupParams{
Body: backup.ScheduleBackupBody{
ServiceID: mongo2ID,
LocationID: locationID,
CronExpression: "0 1 1 1 1",
Name: "testing2",
Description: "testing",
Mode: pointer.ToString(backups.ScheduleBackupBodyModeBACKUPMODEPITR),
Mode: pointer.ToString(backup.ScheduleBackupBodyModeBACKUPMODEPITR),
Enabled: true,
DataModel: pointer.ToString(backups.StartBackupBodyDataModelDATAMODELLOGICAL),
DataModel: pointer.ToString(backup.StartBackupBodyDataModelDATAMODELLOGICAL),
},
Context: pmmapitests.Context,
})
Expand All @@ -313,17 +313,17 @@ func TestScheduleBackup(t *testing.T) {
})

t.Run("physical backups fail when PITR is enabled", func(t *testing.T) {
client := backupClient.Default.BackupsService
_, err := client.ScheduleBackup(&backups.ScheduleBackupParams{
Body: backups.ScheduleBackupBody{
client := backupClient.Default.BackupService
_, err := client.ScheduleBackup(&backup.ScheduleBackupParams{
Body: backup.ScheduleBackupBody{
ServiceID: mongo1ID,
LocationID: locationID,
CronExpression: "0 1 1 1 1",
Name: "some_backup_name",
Description: "testing",
Mode: pointer.ToString(backups.ScheduleBackupBodyModeBACKUPMODEPITR),
Mode: pointer.ToString(backup.ScheduleBackupBodyModeBACKUPMODEPITR),
Enabled: true,
DataModel: pointer.ToString(backups.ScheduleBackupBodyDataModelDATAMODELPHYSICAL),
DataModel: pointer.ToString(backup.ScheduleBackupBodyDataModelDATAMODELPHYSICAL),
},
Context: pmmapitests.Context,
})
Expand All @@ -332,17 +332,17 @@ func TestScheduleBackup(t *testing.T) {
})

t.Run("physical backup snapshots can be scheduled", func(t *testing.T) {
client := backupClient.Default.BackupsService
backupRes, err := client.ScheduleBackup(&backups.ScheduleBackupParams{
Body: backups.ScheduleBackupBody{
client := backupClient.Default.BackupService
backupRes, err := client.ScheduleBackup(&backup.ScheduleBackupParams{
Body: backup.ScheduleBackupBody{
ServiceID: mongo1ID,
LocationID: locationID,
CronExpression: "0 1 1 1 1",
Name: "testing",
Description: "testing",
Mode: pointer.ToString(backups.ScheduleBackupBodyModeBACKUPMODESNAPSHOT),
Mode: pointer.ToString(backup.ScheduleBackupBodyModeBACKUPMODESNAPSHOT),
Enabled: true,
DataModel: pointer.ToString(backups.ScheduleBackupBodyDataModelDATAMODELPHYSICAL),
DataModel: pointer.ToString(backup.ScheduleBackupBodyDataModelDATAMODELPHYSICAL),
},
Context: pmmapitests.Context,
})
Expand All @@ -356,8 +356,8 @@ func TestScheduleBackup(t *testing.T) {

func removeScheduledBackup(t *testing.T, id string) {
t.Helper()
_, err := backupClient.Default.BackupsService.RemoveScheduledBackup(&backups.RemoveScheduledBackupParams{
Body: backups.RemoveScheduledBackupBody{
_, err := backupClient.Default.BackupService.RemoveScheduledBackup(&backup.RemoveScheduledBackupParams{
Body: backup.RemoveScheduledBackupBody{
ScheduledBackupID: id,
},
Context: pmmapitests.Context,
Expand Down
Loading

0 comments on commit 64792d5

Please sign in to comment.