2021-10-12 23:00:24 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
// test package for config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
2021-10-18 21:02:10 +02:00
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2021-10-12 23:00:24 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDummyConfig(t *testing.T) {
|
|
|
|
|
2021-10-18 21:02:10 +02:00
|
|
|
v := viper.New()
|
|
|
|
v.SetConfigType("yaml")
|
2021-10-12 23:00:24 +02:00
|
|
|
var yamlExample = []byte(`
|
|
|
|
settings:
|
|
|
|
systemMountPoint: /media/backive
|
|
|
|
userMountPoint: $HOME/.backive/mounts
|
|
|
|
devices:
|
2021-10-18 21:02:10 +02:00
|
|
|
my_device:
|
|
|
|
uuid: 98237459872398745987
|
|
|
|
owner:
|
2021-10-12 23:00:24 +02:00
|
|
|
backups:
|
2021-10-18 21:02:10 +02:00
|
|
|
my_backup:
|
|
|
|
targetDevice: my_device
|
|
|
|
targetDir: backive_backup
|
|
|
|
sourceDir: /home/user123/stuff
|
|
|
|
scriptPath: /path/to/script
|
|
|
|
frequency: 7 #weekly
|
2021-10-12 23:00:24 +02:00
|
|
|
`)
|
|
|
|
v.ReadConfig(bytes.NewBuffer(yamlExample))
|
|
|
|
var theConfig Configuration
|
|
|
|
err := v.Unmarshal(&theConfig)
|
|
|
|
if err != nil {
|
2021-10-18 21:02:10 +02:00
|
|
|
fmt.Printf("Unable to decode into struct, %v \n", err)
|
2021-10-12 23:00:24 +02:00
|
|
|
panic("Failed!")
|
|
|
|
}
|
|
|
|
fmt.Printf("systemMountpoint is %v \n", theConfig)
|
|
|
|
|
2021-10-18 21:02:10 +02:00
|
|
|
fmt.Printf("System Mountpoint is %v\n", v.Get("settings.systemmountpoint"))
|
2021-10-12 23:00:24 +02:00
|
|
|
}
|