Fix bug migrating config, add test
This commit is contained in:
parent
3bbc715e74
commit
50a6ac9e85
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [v0.5.5] - 2022-04-09
|
||||||
|
|
||||||
|
- Fix a bug which would erase configuration when migrating from v1 to v2 config
|
||||||
|
|
||||||
## [v0.5.4] - 2022-04-07
|
## [v0.5.4] - 2022-04-07
|
||||||
|
|
||||||
- Check the chosen command exists when configuring a profile
|
- Check the chosen command exists when configuring a profile
|
||||||
|
@ -224,6 +224,8 @@ func (cs *ConfigService) LoadConfig() error {
|
|||||||
return fmt.Errorf("Could not read config '%s': %v", path, err)
|
return fmt.Errorf("Could not read config '%s': %v", path, err)
|
||||||
}
|
}
|
||||||
c := Config{}
|
c := Config{}
|
||||||
|
cs.Config = &c
|
||||||
|
|
||||||
err = yaml.Unmarshal(b, &c)
|
err = yaml.Unmarshal(b, &c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not parse YAML config '%s': %v", path, err)
|
return fmt.Errorf("Could not parse YAML config '%s': %v", path, err)
|
||||||
@ -243,8 +245,6 @@ func (cs *ConfigService) LoadConfig() error {
|
|||||||
cs.WriteConfig()
|
cs.WriteConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
cs.Config = &c
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
57
config/config_test.go
Normal file
57
config/config_test.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMigrationV1toV2(t *testing.T) {
|
||||||
|
v2Config := `config_version: 1
|
||||||
|
server:
|
||||||
|
port: 6123
|
||||||
|
address: http://localhost:6123
|
||||||
|
download_path: ./
|
||||||
|
ui:
|
||||||
|
popup_width: 500
|
||||||
|
popup_height: 500
|
||||||
|
profiles:
|
||||||
|
- name: standard video
|
||||||
|
command: youtube-dl
|
||||||
|
args:
|
||||||
|
- --newline
|
||||||
|
- --write-info-json
|
||||||
|
- -f
|
||||||
|
- bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best
|
||||||
|
- name: standard mp3
|
||||||
|
command: youtube-dl
|
||||||
|
args:
|
||||||
|
- --newline
|
||||||
|
- --write-info-json
|
||||||
|
- --extract-audio
|
||||||
|
- --audio-format
|
||||||
|
- mp3
|
||||||
|
`
|
||||||
|
cs := configServiceFromString(v2Config)
|
||||||
|
err := cs.LoadConfig()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("got error when loading config: %s", err)
|
||||||
|
}
|
||||||
|
if cs.Config.ConfigVersion != 2 {
|
||||||
|
t.Errorf("did not migrate version (it is '%d')", cs.Config.ConfigVersion)
|
||||||
|
}
|
||||||
|
if cs.Config.Server.MaximumActiveDownloads != 2 {
|
||||||
|
t.Error("did not add MaximumActiveDownloads")
|
||||||
|
}
|
||||||
|
t.Log(cs.ConfigPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func configServiceFromString(configString string) *ConfigService {
|
||||||
|
tmpFile, _ := os.CreateTemp("", "gropple_test_*.yml")
|
||||||
|
tmpFile.Write([]byte(configString))
|
||||||
|
tmpFile.Close()
|
||||||
|
cs := ConfigService{
|
||||||
|
Config: &Config{},
|
||||||
|
ConfigPath: tmpFile.Name(),
|
||||||
|
}
|
||||||
|
return &cs
|
||||||
|
}
|
2
main.go
2
main.go
@ -23,7 +23,7 @@ var downloads download.Downloads
|
|||||||
var downloadId = 0
|
var downloadId = 0
|
||||||
var configService *config.ConfigService
|
var configService *config.ConfigService
|
||||||
|
|
||||||
var versionInfo = version.Info{CurrentVersion: "v0.5.4"}
|
var versionInfo = version.Info{CurrentVersion: "v0.5.5"}
|
||||||
|
|
||||||
//go:embed web
|
//go:embed web
|
||||||
var webFS embed.FS
|
var webFS embed.FS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user