Skip to content

Commit

Permalink
refactor: add tests for LAGOON_BACKUP_PROD_SCHEDULE (#374)
Browse files Browse the repository at this point in the history
* refactor: add tests for LAGOON_BACKUP_PROD_SCHEDULE

* test: fix retention in testfile

---------

Co-authored-by: Ben Jackson <[email protected]>
  • Loading branch information
rocketeerbkw and shreddedbacon authored Oct 3, 2024
1 parent b47599e commit 05887c3
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
21 changes: 21 additions & 0 deletions cmd/template_backups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,27 @@ func TestBackupTemplateGeneration(t *testing.T) {
templatePath: "testdata/output",
want: "internal/testdata/node/backup-templates/backup-8",
},
{
name: "test11 - custom prod schedule",
args: testdata.GetSeedData(
testdata.TestData{
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
EnvironmentType: "production",
LagoonYAML: "internal/testdata/node/lagoon.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{
Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG",
Value: "enabled",
Scope: "global",
},
{Name: "LAGOON_BACKUP_PROD_SCHEDULE", Value: "2,21 22 * * *", Scope: "build"},
},
}, true),
templatePath: "testoutput",
want: "internal/testdata/node/backup-templates/backup-9",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions docs/buildrequirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ These are all variables that are provided by either core or remote
* `WEEKLY_BACKUP_DEFAULT_RETENTION`
* `DAILY_BACKUP_DEFAULT_RETENTION`
* `HOURLY_BACKUP_DEFAULT_RETENTION`
* `LAGOON_FEATURE_BACKUP_PROD_SCHEDULE` (remote) / `LAGOON_BACKUP_PROD_SCHEDULE` (API)
* `LAGOON_FEATURE_BACKUP_DEV_SCHEDULE` (remote) / `LAGOON_BACKUP_DEV_SCHEDULE` (API)
* `LAGOON_FEATURE_BACKUP_PR_SCHEDULE` (remote) / `LAGOON_BACKUP_PR_SCHEDULE` (API)
* `LAGOON_FEATURE_BACKUP_DEV_RETENTION` (remote) / `LAGOON_BACKUP_DEV_RETENTION` (API)
* `LAGOON_FEATURE_BACKUP_PR_RETENTION` (remote) / `LAGOON_BACKUP_PR_RETENTION` (API)
* `K8UP_WEEKLY_RANDOM_FEATURE_FLAG`
36 changes: 36 additions & 0 deletions internal/generator/backups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,42 @@ func Test_generateBackupValues(t *testing.T) {
},
},
},
{
name: "test20- prod schedule from lagoon api variable",
args: args{
buildValues: &BuildValues{
BuildType: "branch",
EnvironmentType: "production",
Project: "example-project",
Namespace: "example-com-main",
DefaultBackupSchedule: "M H(22-2) * * *",
LagoonYAML: lagoon.YAML{},
},
mergedVariables: []lagoon.EnvironmentVariable{
{Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG", Value: "enabled", Scope: "global"},
{Name: "LAGOON_BACKUP_PROD_SCHEDULE", Value: "M/15 23 * * 0-5", Scope: "build"},
},
},
want: &BuildValues{
BuildType: "branch",
EnvironmentType: "production",
Project: "example-project",
Namespace: "example-com-main",
DefaultBackupSchedule: "M H(22-2) * * *",
Backup: BackupConfiguration{
BackupSchedule: "1,16,31,46 23 * * 0-5",
CheckSchedule: "31 6 * * 1",
PruneSchedule: "31 4 * * 0",
S3BucketName: "baas-example-project",
PruneRetention: PruneRetention{
Hourly: 0,
Daily: 7,
Weekly: 6,
Monthly: 0,
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
apiVersion: backup.appuio.ch/v1alpha1
kind: Schedule
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: k8up-lagoon-backup-schedule
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: k8up-schedule
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: k8up-lagoon-backup-schedule
lagoon.sh/service-type: k8up-schedule
lagoon.sh/template: k8up-schedule-0.1.0
name: k8up-lagoon-backup-schedule
spec:
backend:
repoPasswordSecretRef:
key: repo-pw
name: baas-repo-pw
s3:
bucket: baas-example-project
backup:
resources: {}
schedule: 2,21 22 * * *
check:
resources: {}
schedule: 48 5 * * 1
prune:
resources: {}
retention:
keepDaily: 7
keepWeekly: 6
schedule: 48 3 * * 0
resourceRequirementsTemplate: {}
status: {}

0 comments on commit 05887c3

Please sign in to comment.