Skip to content

Commit b9f11fa

Browse files
committed
Removed 'maintenance' config block, was deprecated and replaced by 'ScheduledTask[]' in v0.14
1 parent a405191 commit b9f11fa

9 files changed

Lines changed: 95 additions & 114 deletions

src/authentication_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,6 @@ func TestCustomCodeSetup(t *testing.T) {
561561
os.Remove("../test/test1.db")
562562
os.Remove("../test/test2.db")
563563

564-
errCode := 444
565-
566564
// test1 has structs.Credentials, test2 uses an auth query
567565
// init statements are also tested here
568566
cfg := structs.Config{
@@ -577,7 +575,7 @@ func TestCustomCodeSetup(t *testing.T) {
577575
},
578576
Auth: &structs.Auth{
579577
Mode: "HTTP",
580-
CustomErrorCode: &errCode,
578+
CustomErrorCode: utils.Ptr(444),
581579
ByCredentials: []structs.CredentialsCfg{
582580
{
583581
User: "pietro",
@@ -602,7 +600,7 @@ func TestCustomCodeSetup(t *testing.T) {
602600
},
603601
Auth: &structs.Auth{
604602
Mode: "inline", // check if case insensitive
605-
CustomErrorCode: &errCode,
603+
CustomErrorCode: utils.Ptr(444),
606604
ByQuery: "SELECT 1 FROM AUTH WHERE USER = :user AND PASS = :password",
607605
},
608606
},

src/cli_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,18 @@ func TestConfigs(t *testing.T) {
8989
assert(t, cfgdb.ConfigFilePath != "", "the db is not correctly marked regarding having config file")
9090
assert(t, cfgdb.Auth.Mode == authModeHttp, "the db has not the correct Auth Mode")
9191
assert(t, cfgdb.Auth.ByQuery == "", "the db has ByQuery with a value")
92-
assert(t, len(cfgdb.Auth.ByCredentials) == 2, "the db has not the correct number of credentials")
93-
assert(t, cfgdb.Auth.ByCredentials[0].User == "myUser1", "the db has not the correct first user")
94-
assert(t, cfgdb.Auth.ByCredentials[0].HashedPassword == "", "the db has not the correct first hashed password")
95-
assert(t, cfgdb.Auth.ByCredentials[1].User == "myUser2", "the db has not the correct second user")
96-
assert(t, len(cfgdb.Auth.ByCredentials[1].HashedPassword) == 64, "the db has not the correct second hashed password")
92+
assert(t, len(cfgdb.Auth.ByCredentials) == 1, "the db has not the correct number of credentials")
93+
assert(t, cfgdb.Auth.ByCredentials[0].User == "myUser", "the db has not the correct user")
94+
assert(t, len(cfgdb.Auth.ByCredentials[0].HashedPassword) == 60, "the db has not the correct hashed password")
9795
assert(t, *cfgdb.DatabaseDef.DisableWALMode, "the db has not the correct WAL mode")
9896
assert(t, cfgdb.DatabaseDef.ReadOnly, "the db has not the correct ReadOnly value")
9997
assert(t, !cfgdb.UseOnlyStoredStatements, "the db has not the correct UseOnlyStoredStatements value")
10098
assert(t, cfgdb.CORSOrigin == "", "the db has not the correct CORSOrigin value")
101-
assert(t, *cfgdb.Maintenance.Schedule == "0 0 * * *", "the db has not the correct Maintenance.Schedule value")
102-
assert(t, cfgdb.Maintenance.DoVacuum, "the db has not the correct Maintenance.DoVacuum value")
103-
assert(t, cfgdb.Maintenance.DoBackup, "the db has not the correct Maintenance.DoBackup value")
104-
assert(t, cfgdb.Maintenance.BackupTemplate == "~/first_%s.db", "the db has not the correct Maintenance.BackupTemplate value")
105-
assert(t, cfgdb.Maintenance.NumFiles == 3, "the db has not the correct Maintenance.NumFiles value")
99+
assert(t, *cfgdb.ScheduledTasks[0].Schedule == "0 0 * * *", "the db has not the correct ScheduledTasks.Schedule value")
100+
assert(t, cfgdb.ScheduledTasks[0].DoVacuum, "the db has not the correct ScheduledTasks.DoVacuum value")
101+
assert(t, cfgdb.ScheduledTasks[0].DoBackup, "the db has not the correct ScheduledTasks.DoBackup value")
102+
assert(t, cfgdb.ScheduledTasks[0].BackupTemplate == "~/first_%s.db", "the db has not the correct ScheduledTasks.BackupTemplate value")
103+
assert(t, cfgdb.ScheduledTasks[0].NumFiles == 3, "the db has not the correct ScheduledTasks.NumFiles value")
106104
assert(t, len(cfgdb.InitStatements) == 0, "the db has not the correct number of init statements")
107105
assert(t, len(cfgdb.StoredStatement) == 0, "the db has not the correct number of stored statements")
108106

@@ -117,7 +115,7 @@ func TestConfigs(t *testing.T) {
117115
assert(t, !cfgdb.DatabaseDef.ReadOnly, "the db has not the correct ReadOnly value")
118116
assert(t, cfgdb.UseOnlyStoredStatements, "the db has not the correct UseOnlyStoredStatements value")
119117
assert(t, cfgdb.CORSOrigin != "", "the db has not the correct CORSOrigin value")
120-
assert(t, cfgdb.Maintenance == nil, "the db has not the correct Maintenance value")
118+
assert(t, cfgdb.ScheduledTasks == nil, "the db has not the correct ScheduledTasks value")
121119
assert(t, len(cfgdb.InitStatements) == 4, "the db has not the correct number of init statements")
122120
assert(t, len(cfgdb.StoredStatement) == 2, "the db has not the correct number of stored statements")
123121
}

src/sched_tasks_test.go

Lines changed: 69 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ import (
2828
"github.com/robfig/cron/v3"
2929
)
3030

31-
// The post-0.14 "scheduledTasks" structure is only actually tested in TestAtStartupMultiple, but the contents of the
32-
// "maintenance" structure are copied to it anyway so the old tests for "maintenance" should suffice for the new one too
33-
3431
func cleanSchedTasksFiles(cfg structs.Config) {
3532
for i := range cfg.Databases {
3633
os.Remove(*cfg.Databases[i].DatabaseDef.Path)
37-
bkpDir, bkpFile := filepath.Dir(cfg.Databases[i].Maintenance.BackupTemplate),
38-
filepath.Base(cfg.Databases[i].Maintenance.BackupTemplate)
34+
bkpDir, bkpFile := filepath.Dir(cfg.Databases[i].ScheduledTasks[0].BackupTemplate),
35+
filepath.Base(cfg.Databases[i].ScheduledTasks[0].BackupTemplate)
3936
list, _ := filepath.Glob(fmt.Sprintf(filepath.Join(bkpDir, bkpFile), bkpTimeGlob))
4037
for i := range list {
4138
os.Remove(list[i])
@@ -58,8 +55,6 @@ func TestSchedTasks(t *testing.T) {
5855
defer os.Remove("../test/test2.db")
5956
defer Shutdown()
6057

61-
sched := "* * * * *"
62-
6358
cfg := structs.Config{
6459
Bindhost: "0.0.0.0",
6560
Port: 12321,
@@ -70,25 +65,29 @@ func TestSchedTasks(t *testing.T) {
7065
Path: utils.Ptr("../test/test1.db"),
7166
DisableWALMode: utils.Ptr(true), // generate only ".db" files
7267
},
73-
Maintenance: &structs.ScheduledTask{
74-
Schedule: &sched,
75-
DoVacuum: false,
76-
DoBackup: true,
77-
BackupTemplate: "../test/test1_%s.db",
78-
NumFiles: 1,
68+
ScheduledTasks: []structs.ScheduledTask{
69+
structs.ScheduledTask{
70+
Schedule: utils.Ptr("* * * * *"),
71+
DoVacuum: false,
72+
DoBackup: true,
73+
BackupTemplate: "../test/test1_%s.db",
74+
NumFiles: 1,
75+
},
7976
},
8077
}, {
8178
DatabaseDef: structs.DatabaseDef{
8279
Id: utils.Ptr("test2"),
8380
Path: utils.Ptr("../test/test2.db"),
8481
DisableWALMode: utils.Ptr(true), // generate only ".db" files
8582
},
86-
Maintenance: &structs.ScheduledTask{
87-
Schedule: &sched,
88-
DoVacuum: false,
89-
DoBackup: true,
90-
BackupTemplate: "../test/test2_%s.db",
91-
NumFiles: 1,
83+
ScheduledTasks: []structs.ScheduledTask{
84+
structs.ScheduledTask{
85+
Schedule: utils.Ptr("* * * * *"),
86+
DoVacuum: false,
87+
DoBackup: true,
88+
BackupTemplate: "../test/test2_%s.db",
89+
NumFiles: 1,
90+
},
9291
},
9392
},
9493
},
@@ -122,8 +121,8 @@ func TestSchedTasks(t *testing.T) {
122121
time.Sleep(time.Minute)
123122

124123
now := time.Now().Format(bkpTimeFormat)
125-
bk1 := fmt.Sprintf(cfg.Databases[0].Maintenance.BackupTemplate, now)
126-
bk2 := fmt.Sprintf(cfg.Databases[1].Maintenance.BackupTemplate, now)
124+
bk1 := fmt.Sprintf(cfg.Databases[0].ScheduledTasks[0].BackupTemplate, now)
125+
bk2 := fmt.Sprintf(cfg.Databases[1].ScheduledTasks[0].BackupTemplate, now)
127126

128127
if !utils.FileExists(bk1) || !utils.FileExists(bk2) {
129128
t.Error("backup file not created")
@@ -140,8 +139,8 @@ func TestSchedTasks(t *testing.T) {
140139
time.Sleep(time.Minute)
141140

142141
now = time.Now().Format(bkpTimeFormat)
143-
bk3 := fmt.Sprintf(cfg.Databases[0].Maintenance.BackupTemplate, now)
144-
bk4 := fmt.Sprintf(cfg.Databases[1].Maintenance.BackupTemplate, now)
142+
bk3 := fmt.Sprintf(cfg.Databases[0].ScheduledTasks[0].BackupTemplate, now)
143+
bk4 := fmt.Sprintf(cfg.Databases[1].ScheduledTasks[0].BackupTemplate, now)
145144

146145
if !utils.FileExists(bk3) || !utils.FileExists(bk4) {
147146
t.Error("backup file not created, the second time")
@@ -162,8 +161,6 @@ func TestDDBSchedTasks(t *testing.T) {
162161
defer os.Remove("../test/test2.zip")
163162
defer Shutdown()
164163

165-
sched := "* * * * *"
166-
167164
cfg := structs.Config{
168165
Bindhost: "0.0.0.0",
169166
Port: 12321,
@@ -174,25 +171,29 @@ func TestDDBSchedTasks(t *testing.T) {
174171
Id: utils.Ptr("test1"),
175172
Path: utils.Ptr("../test/test1.db"),
176173
},
177-
Maintenance: &structs.ScheduledTask{
178-
Schedule: &sched,
179-
DoVacuum: false,
180-
DoBackup: true,
181-
BackupTemplate: "../test/test1_%s.zip",
182-
NumFiles: 1,
174+
ScheduledTasks: []structs.ScheduledTask{
175+
structs.ScheduledTask{
176+
Schedule: utils.Ptr("* * * * *"),
177+
DoVacuum: false,
178+
DoBackup: true,
179+
BackupTemplate: "../test/test1_%s.db",
180+
NumFiles: 1,
181+
},
183182
},
184183
}, {
185184
DatabaseDef: structs.DatabaseDef{
186185
Type: utils.Ptr("DUCKDB"),
187186
Id: utils.Ptr("test2"),
188187
Path: utils.Ptr("../test/test2.db"),
189188
},
190-
Maintenance: &structs.ScheduledTask{
191-
Schedule: &sched,
192-
DoVacuum: false,
193-
DoBackup: true,
194-
BackupTemplate: "../test/test2_%s.zip",
195-
NumFiles: 1,
189+
ScheduledTasks: []structs.ScheduledTask{
190+
structs.ScheduledTask{
191+
Schedule: utils.Ptr("* * * * *"),
192+
DoVacuum: false,
193+
DoBackup: true,
194+
BackupTemplate: "../test/test2_%s.db",
195+
NumFiles: 1,
196+
},
196197
},
197198
},
198199
},
@@ -226,8 +227,8 @@ func TestDDBSchedTasks(t *testing.T) {
226227
time.Sleep(time.Minute)
227228

228229
now := time.Now().Format(bkpTimeFormat)
229-
bk1 := fmt.Sprintf(cfg.Databases[0].Maintenance.BackupTemplate, now)
230-
bk2 := fmt.Sprintf(cfg.Databases[1].Maintenance.BackupTemplate, now)
230+
bk1 := fmt.Sprintf(cfg.Databases[0].ScheduledTasks[0].BackupTemplate, now)
231+
bk2 := fmt.Sprintf(cfg.Databases[1].ScheduledTasks[0].BackupTemplate, now)
231232

232233
if !utils.FileExists(bk1) || !utils.FileExists(bk2) {
233234
t.Error("backup file not created")
@@ -244,8 +245,8 @@ func TestDDBSchedTasks(t *testing.T) {
244245
time.Sleep(time.Minute)
245246

246247
now = time.Now().Format(bkpTimeFormat)
247-
bk3 := fmt.Sprintf(cfg.Databases[0].Maintenance.BackupTemplate, now)
248-
bk4 := fmt.Sprintf(cfg.Databases[1].Maintenance.BackupTemplate, now)
248+
bk3 := fmt.Sprintf(cfg.Databases[0].ScheduledTasks[0].BackupTemplate, now)
249+
bk4 := fmt.Sprintf(cfg.Databases[1].ScheduledTasks[0].BackupTemplate, now)
249250

250251
if !utils.FileExists(bk3) || !utils.FileExists(bk4) {
251252
t.Error("backup file not created, the second time")
@@ -265,8 +266,6 @@ func TestSchedTasksWithReadOnly(t *testing.T) {
265266
defer os.Remove("../test/test.db")
266267
defer Shutdown()
267268

268-
sched := "* * * * *"
269-
270269
cfg := structs.Config{
271270
Bindhost: "0.0.0.0",
272271
Port: 12321,
@@ -278,12 +277,14 @@ func TestSchedTasksWithReadOnly(t *testing.T) {
278277
DisableWALMode: utils.Ptr(true), // generate only ".db" files
279278
ReadOnly: true,
280279
},
281-
Maintenance: &structs.ScheduledTask{
282-
Schedule: &sched,
283-
DoVacuum: false,
284-
DoBackup: true,
285-
BackupTemplate: "../test/test_%s.db",
286-
NumFiles: 1,
280+
ScheduledTasks: []structs.ScheduledTask{
281+
structs.ScheduledTask{
282+
Schedule: utils.Ptr("* * * * *"),
283+
DoVacuum: false,
284+
DoBackup: true,
285+
BackupTemplate: "../test/test_%s.db",
286+
NumFiles: 1,
287+
},
287288
},
288289
},
289290
},
@@ -297,7 +298,7 @@ func TestSchedTasksWithReadOnly(t *testing.T) {
297298
time.Sleep(time.Minute)
298299

299300
now := time.Now().Format(bkpTimeFormat)
300-
bk1 := fmt.Sprintf(cfg.Databases[0].Maintenance.BackupTemplate, now)
301+
bk1 := fmt.Sprintf(cfg.Databases[0].ScheduledTasks[0].BackupTemplate, now)
301302

302303
if !utils.FileExists(bk1) {
303304
t.Error("backup file not created")
@@ -310,8 +311,6 @@ func TestSchedTasksWithStatement(t *testing.T) {
310311
defer os.Remove("../test/test.db")
311312
defer Shutdown()
312313

313-
sched := "* * * * *"
314-
315314
cfg := structs.Config{
316315
Bindhost: "0.0.0.0",
317316
Port: 12321,
@@ -322,11 +321,13 @@ func TestSchedTasksWithStatement(t *testing.T) {
322321
Path: utils.Ptr("../test/test.db"),
323322
DisableWALMode: utils.Ptr(true), // generate only ".db" files
324323
},
325-
Maintenance: &structs.ScheduledTask{
326-
Schedule: &sched,
327-
DoVacuum: false,
328-
DoBackup: false,
329-
Statements: []string{"INSERT INTO tbl VALUES (17)"},
324+
ScheduledTasks: []structs.ScheduledTask{
325+
structs.ScheduledTask{
326+
Schedule: utils.Ptr("* * * * *"),
327+
DoVacuum: false,
328+
DoBackup: false,
329+
Statements: []string{"INSERT INTO tbl VALUES (17)"},
330+
},
330331
},
331332
InitStatements: []string{"CREATE TABLE tbl (num INTEGER)"},
332333
},
@@ -360,8 +361,6 @@ func TestAtStartup(t *testing.T) {
360361
defer os.Remove("../test/test.db")
361362
defer Shutdown()
362363

363-
t_r_u_e := true
364-
365364
cfg := structs.Config{
366365
Bindhost: "0.0.0.0",
367366
Port: 12321,
@@ -372,12 +371,14 @@ func TestAtStartup(t *testing.T) {
372371
Path: utils.Ptr("../test/test.db"),
373372
DisableWALMode: utils.Ptr(true), // generate only ".db" files
374373
},
375-
Maintenance: &structs.ScheduledTask{
376-
AtStartup: &t_r_u_e,
377-
DoVacuum: false,
378-
DoBackup: true,
379-
BackupTemplate: "../test/test_%s.db",
380-
NumFiles: 1,
374+
ScheduledTasks: []structs.ScheduledTask{
375+
structs.ScheduledTask{
376+
AtStartup: utils.Ptr(true),
377+
DoVacuum: false,
378+
DoBackup: true,
379+
BackupTemplate: "../test/test_%s.db",
380+
NumFiles: 1,
381+
},
381382
},
382383
},
383384
},
@@ -391,7 +392,7 @@ func TestAtStartup(t *testing.T) {
391392

392393
time.Sleep(3 * time.Second)
393394

394-
bk1 := fmt.Sprintf(cfg.Databases[0].Maintenance.BackupTemplate, now)
395+
bk1 := fmt.Sprintf(cfg.Databases[0].ScheduledTasks[0].BackupTemplate, now)
395396

396397
if !utils.FileExists(bk1) {
397398
t.Error("backup file not created")
@@ -403,8 +404,6 @@ func TestAtStartupMultiple(t *testing.T) {
403404
defer os.Remove("../test/test.db")
404405
defer Shutdown()
405406

406-
t_r_u_e := true
407-
408407
cfg := structs.Config{
409408
Bindhost: "0.0.0.0",
410409
Port: 12321,
@@ -420,12 +419,12 @@ func TestAtStartupMultiple(t *testing.T) {
420419
},
421420
ScheduledTasks: []structs.ScheduledTask{
422421
{
423-
AtStartup: &t_r_u_e,
422+
AtStartup: utils.Ptr(true),
424423
DoVacuum: false,
425424
DoBackup: false,
426425
Statements: []string{"INSERT INTO TMP VALUES (1)"},
427426
}, {
428-
AtStartup: &t_r_u_e,
427+
AtStartup: utils.Ptr(true),
429428
DoVacuum: false,
430429
DoBackup: false,
431430
Statements: []string{"INSERT INTO TMP VALUES (2)"},

0 commit comments

Comments
 (0)