mirror of
https://github.com/octoleo/restic.git
synced 2024-12-11 13:52:31 +00:00
f903db492c
In order to change the backend initialization in `global.go` to be able to generically call cfg.ApplyEnvironment() for supported backends, the `interface{}` returned by `ParseConfig` must contain a pointer to the configuration. An alternative would be to use reflection to convert the type from `interface{}(Config)` to `interface{}(*Config)` (from value to pointer type). However, this would just complicate the type mess further.
29 lines
562 B
Go
29 lines
562 B
Go
package test
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
type ConfigTestData[C comparable] struct {
|
|
S string
|
|
Cfg C
|
|
}
|
|
|
|
func ParseConfigTester[C comparable](t *testing.T, parser func(s string) (*C, error), tests []ConfigTestData[C]) {
|
|
for i, test := range tests {
|
|
t.Run(fmt.Sprint(i), func(t *testing.T) {
|
|
cfg, err := parser(test.S)
|
|
if err != nil {
|
|
t.Fatalf("%s failed: %v", test.S, err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(*cfg, test.Cfg) {
|
|
t.Fatalf("input: %s\n wrong config, want:\n %#v\ngot:\n %#v",
|
|
test.S, test.Cfg, *cfg)
|
|
}
|
|
})
|
|
}
|
|
}
|