Dan Anglin
19eb9b20be
This commit adds a feature to load Pominal configuration from a JSON configuration file. A new data type called PominalConfig was created for the purpose of configuring Pominal. A new factory function called newPominalConfig was created which takes the path to the JSON configuration file and the flag overrides and generates the new PominalConfig value. Here, the JSON config is parsed to create the initial configuration and any flag overrides can override the corresponding fields in the PominalConfig object. Currently only the sessions times and the maximum work sessions per Pominal cycle have flag overrides. Additionally users can now configure custom notification messages for each session type from the configuration file. There are currently no flag overrides for these. This commit resolves dananglin/Pominal#1
135 lines
3.8 KiB
Go
135 lines
3.8 KiB
Go
/*
|
|
Pominal
|
|
Copyright (C) 2020 Daniel Anglin
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package main
|
|
|
|
var configTestCases = []struct {
|
|
name string
|
|
description string
|
|
file string
|
|
workTimeFlag string
|
|
shortBreakTimeFlag string
|
|
longBreakTimeFlag string
|
|
maxWorkSessionsFlag int
|
|
expectedConfiguration PominalConfig
|
|
}{
|
|
{
|
|
name: "Test case 1",
|
|
description: "When the configuration file and flag overrides are not set.",
|
|
file: "",
|
|
workTimeFlag: "",
|
|
shortBreakTimeFlag: "",
|
|
longBreakTimeFlag: "",
|
|
maxWorkSessionsFlag: 0,
|
|
expectedConfiguration: PominalConfig{
|
|
MaxWorkSessions: defaultMaxWorkSessions,
|
|
Sessions: Sessions{
|
|
Work: SessionConfig{
|
|
Duration: defaultWorkTime,
|
|
NotificationMessage: "",
|
|
},
|
|
ShortBreak: SessionConfig{
|
|
Duration: defaultShortBreakTime,
|
|
NotificationMessage: "",
|
|
},
|
|
LongBreak: SessionConfig{
|
|
Duration: defaultLongBreakTime,
|
|
NotificationMessage: "",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Test case 2",
|
|
description: "When the configuration file is set and the flag overrides are not set.",
|
|
file: "./testdata/pominal.json",
|
|
workTimeFlag: "",
|
|
shortBreakTimeFlag: "",
|
|
longBreakTimeFlag: "",
|
|
maxWorkSessionsFlag: 0,
|
|
expectedConfiguration: PominalConfig{
|
|
MaxWorkSessions: 2,
|
|
Sessions: Sessions{
|
|
Work: SessionConfig{
|
|
Duration: "30m",
|
|
NotificationMessage: "Time for work!",
|
|
},
|
|
ShortBreak: SessionConfig{
|
|
Duration: "10m",
|
|
NotificationMessage: "Take a short break.",
|
|
},
|
|
LongBreak: SessionConfig{
|
|
Duration: "30m",
|
|
NotificationMessage: "Long break time! Put the kettle on.",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Test case 3",
|
|
description: "When the configuration file is set and some flags overrides are set.",
|
|
file: "./testdata/pominal.json",
|
|
workTimeFlag: "100m",
|
|
shortBreakTimeFlag: "",
|
|
longBreakTimeFlag: "",
|
|
maxWorkSessionsFlag: 6,
|
|
expectedConfiguration: PominalConfig{
|
|
MaxWorkSessions: 6,
|
|
Sessions: Sessions{
|
|
Work: SessionConfig{
|
|
Duration: "100m",
|
|
NotificationMessage: "Time for work!",
|
|
},
|
|
ShortBreak: SessionConfig{
|
|
Duration: "10m",
|
|
NotificationMessage: "Take a short break.",
|
|
},
|
|
LongBreak: SessionConfig{
|
|
Duration: "30m",
|
|
NotificationMessage: "Long break time! Put the kettle on.",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Test case 4",
|
|
description: "When the configuration file is not set and all the flag overrides are set.",
|
|
file: "",
|
|
workTimeFlag: "100m",
|
|
shortBreakTimeFlag: "5m",
|
|
longBreakTimeFlag: "60m",
|
|
maxWorkSessionsFlag: 3,
|
|
expectedConfiguration: PominalConfig{
|
|
MaxWorkSessions: 3,
|
|
Sessions: Sessions{
|
|
Work: SessionConfig{
|
|
Duration: "100m",
|
|
NotificationMessage: "",
|
|
},
|
|
ShortBreak: SessionConfig{
|
|
Duration: "5m",
|
|
NotificationMessage: "",
|
|
},
|
|
LongBreak: SessionConfig{
|
|
Duration: "60m",
|
|
NotificationMessage: "",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|