2023-09-03 00:16:19 +00:00
|
|
|
package settings
|
|
|
|
|
|
|
|
import (
|
2023-09-03 17:28:00 +00:00
|
|
|
"log"
|
2023-09-03 00:16:19 +00:00
|
|
|
"testing"
|
2023-09-03 17:28:00 +00:00
|
|
|
|
|
|
|
"github.com/goccy/go-yaml"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
2023-09-03 00:16:19 +00:00
|
|
|
)
|
|
|
|
|
2023-09-03 17:28:00 +00:00
|
|
|
func TestConfigLoadChanged(t *testing.T) {
|
2023-09-10 14:35:30 +00:00
|
|
|
yamlData := loadConfigFile("./testingConfig.yaml")
|
2023-09-03 17:28:00 +00:00
|
|
|
// Marshal the YAML data to a more human-readable format
|
|
|
|
newConfig := setDefaults()
|
|
|
|
GlobalConfiguration := setDefaults()
|
|
|
|
|
|
|
|
err := yaml.Unmarshal(yamlData, &newConfig)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error unmarshaling YAML data: %v", err)
|
|
|
|
}
|
|
|
|
// Use go-cmp to compare the two structs
|
|
|
|
if diff := cmp.Diff(newConfig, GlobalConfiguration); diff == "" {
|
|
|
|
t.Errorf("No change when there should have been (-want +got):\n%s", diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigLoadSpecificValues(t *testing.T) {
|
2023-09-10 14:35:30 +00:00
|
|
|
yamlData := loadConfigFile("./testingConfig.yaml")
|
2023-09-03 17:28:00 +00:00
|
|
|
// Marshal the YAML data to a more human-readable format
|
|
|
|
newConfig := setDefaults()
|
|
|
|
GlobalConfiguration := setDefaults()
|
|
|
|
|
|
|
|
err := yaml.Unmarshal(yamlData, &newConfig)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error unmarshaling YAML data: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if GlobalConfiguration.Auth.Method == newConfig.Auth.Method {
|
|
|
|
log.Fatalf("Differences should have been found, but were not on Auth method")
|
|
|
|
}
|
|
|
|
if GlobalConfiguration.UserDefaults.HideDotfiles == newConfig.UserDefaults.HideDotfiles {
|
|
|
|
log.Fatalf("Differences should have been found, but were not on Auth method")
|
|
|
|
}
|
2023-09-03 00:16:19 +00:00
|
|
|
}
|