Skip to content

Commit c0ff21f

Browse files
committed
add test coverage
1 parent 7569b97 commit c0ff21f

File tree

2 files changed

+108
-30
lines changed

2 files changed

+108
-30
lines changed

internal/orchestrator/repo/repo_test.go

+52-26
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,65 @@ var configForTest = &v1.Config{
2020
func TestBackup(t *testing.T) {
2121
t.Parallel()
2222

23-
repo := t.TempDir()
2423
testData := test.CreateTestData(t)
2524

26-
// create a new repo with cache disabled for testing
27-
r := &v1.Repo{
28-
Id: "test",
29-
Uri: repo,
30-
Password: "test",
31-
Flags: []string{"--no-cache"},
32-
}
33-
34-
plan := &v1.Plan{
35-
Id: "test",
36-
Repo: "test",
37-
Paths: []string{testData},
25+
tcs := []struct {
26+
name string
27+
repo *v1.Repo
28+
plan *v1.Plan
29+
}{
30+
{
31+
name: "backup",
32+
repo: &v1.Repo{
33+
Id: "test",
34+
Uri: t.TempDir(),
35+
Password: "test",
36+
},
37+
plan: &v1.Plan{
38+
Id: "test",
39+
Repo: "test",
40+
Paths: []string{testData},
41+
},
42+
},
43+
{
44+
name: "backup with ionice",
45+
repo: &v1.Repo{
46+
Id: "test",
47+
Uri: t.TempDir(),
48+
Password: "test",
49+
CommandPrefix: &v1.CommandPrefix{
50+
IoNice: v1.CommandPrefix_IO_BEST_EFFORT_LOW,
51+
CpuNice: v1.CommandPrefix_CPU_HIGH,
52+
},
53+
},
54+
plan: &v1.Plan{
55+
Id: "test",
56+
Repo: "test",
57+
Paths: []string{testData},
58+
},
59+
},
3860
}
3961

40-
orchestrator, err := NewRepoOrchestrator(configForTest, r, helpers.ResticBinary(t))
41-
if err != nil {
42-
t.Fatalf("failed to create repo orchestrator: %v", err)
43-
}
62+
for _, tc := range tcs {
63+
t.Run(tc.name, func(t *testing.T) {
64+
orchestrator, err := NewRepoOrchestrator(configForTest, tc.repo, helpers.ResticBinary(t))
65+
if err != nil {
66+
t.Fatalf("failed to create repo orchestrator: %v", err)
67+
}
4468

45-
summary, err := orchestrator.Backup(context.Background(), plan, nil)
46-
if err != nil {
47-
t.Fatalf("backup error: %v", err)
48-
}
69+
summary, err := orchestrator.Backup(context.Background(), tc.plan, nil)
70+
if err != nil {
71+
t.Fatalf("backup error: %v", err)
72+
}
4973

50-
if summary.SnapshotId == "" {
51-
t.Fatal("expected snapshot id")
52-
}
74+
if summary.SnapshotId == "" {
75+
t.Fatal("expected snapshot id")
76+
}
5377

54-
if summary.FilesNew != 100 {
55-
t.Fatalf("expected 100 new files, got %d", summary.FilesNew)
78+
if summary.FilesNew != 100 {
79+
t.Fatalf("expected 100 new files, got %d", summary.FilesNew)
80+
}
81+
})
5682
}
5783
}
5884

webui/src/views/AddRepoModal.tsx

+56-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ import {
1313
FormInstance,
1414
Collapse,
1515
Checkbox,
16+
Select,
1617
} from "antd";
1718
import React, { useEffect, useState } from "react";
1819
import { useShowModal } from "../components/ModalManager";
19-
import { Hook, Repo } from "../../gen/ts/v1/config_pb";
20+
import {
21+
CommandPrefix_CPUNiceLevel,
22+
CommandPrefix_IONiceLevel,
23+
Hook,
24+
Repo,
25+
} from "../../gen/ts/v1/config_pb";
2026
import { URIAutocomplete } from "../components/URIAutocomplete";
2127
import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
2228
import { formatErrorAlert, useAlertApi } from "../components/Alerts";
@@ -31,6 +37,7 @@ import { ConfirmButton } from "../components/SpinButton";
3137
import { useConfig } from "../components/ConfigProvider";
3238
import Cron from "react-js-cron";
3339
import { ScheduleFormItem } from "../components/ScheduleFormItem";
40+
import { proto3 } from "@bufbuild/protobuf";
3441

3542
export const AddRepoModal = ({ template }: { template: Repo | null }) => {
3643
const [confirmLoading, setConfirmLoading] = useState(false);
@@ -97,14 +104,15 @@ export const AddRepoModal = ({ template }: { template: Repo | null }) => {
97104
});
98105

99106
if (template !== null) {
107+
const configCopy = config.clone();
100108
// We are in the edit repo flow, update the repo in the config
101-
const idx = config.repos!.findIndex((r) => r.id === template!.id);
109+
const idx = configCopy.repos!.findIndex((r) => r.id === template!.id);
102110
if (idx === -1) {
103111
alertsApi.error("Can't update repo, not found");
104112
return;
105113
}
106-
config.repos![idx] = repo;
107-
setConfig(await backrestService.setConfig(config));
114+
configCopy.repos![idx] = repo;
115+
setConfig(await backrestService.setConfig(configCopy));
108116
showModal(null);
109117
alertsApi.success("Updated repo " + repo.uri);
110118

@@ -486,6 +494,50 @@ export const AddRepoModal = ({ template }: { template: Repo | null }) => {
486494
<ScheduleFormItem name={["checkPolicy", "schedule"]} />
487495
</Form.Item>
488496

497+
{/* Repo.commandPrefix */}
498+
<Form.Item
499+
label={
500+
<Tooltip
501+
title={
502+
<span>
503+
Modifiers for the backup operation e.g. set the CPU or IO
504+
priority. Currently only available on unix systems.
505+
</span>
506+
}
507+
>
508+
Command Modifiers
509+
</Tooltip>
510+
}
511+
>
512+
<Row>
513+
<Col span={12}>
514+
<Form.Item name={["commandPrefix", "ioNice"]} required={false}>
515+
<Select
516+
allowClear
517+
style={{ width: "100%" }}
518+
placeholder="Select an IO priority"
519+
options={proto3
520+
.getEnumType(CommandPrefix_IONiceLevel)
521+
.values.map((v) => ({ label: v.name, value: v.name }))}
522+
/>
523+
</Form.Item>
524+
</Col>
525+
526+
<Col span={12}>
527+
<Form.Item name={["commandPrefix", "cpuNice"]} required={false}>
528+
<Select
529+
allowClear
530+
style={{ width: "100%" }}
531+
placeholder="Select a CPU priority"
532+
options={proto3
533+
.getEnumType(CommandPrefix_CPUNiceLevel)
534+
.values.map((v) => ({ label: v.name, value: v.name }))}
535+
/>
536+
</Form.Item>
537+
</Col>
538+
</Row>
539+
</Form.Item>
540+
489541
<Form.Item
490542
label={
491543
<Tooltip

0 commit comments

Comments
 (0)