42 lines
634 B
Go
42 lines
634 B
Go
package util
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewConfig(t *testing.T) {
|
|
|
|
f, err := os.CreateTemp("", "testconfig")
|
|
if err != nil {
|
|
t.Errorf(err.Error())
|
|
}
|
|
defer os.Remove(f.Name()) // clean up temp dir
|
|
|
|
type c struct {
|
|
Key1 string
|
|
Key2 string
|
|
}
|
|
want := c{
|
|
Key1: "val1",
|
|
Key2: "val2",
|
|
}
|
|
yaml := `key1: val1
|
|
key2: val2`
|
|
|
|
if _, err := f.Write([]byte(yaml)); err != nil {
|
|
t.Errorf(err.Error())
|
|
}
|
|
if err := f.Close(); err != nil {
|
|
t.Errorf(err.Error())
|
|
}
|
|
|
|
have, err := NewConfig[c](f.Name())
|
|
if err != nil {
|
|
t.Errorf(err.Error())
|
|
}
|
|
if want != *have {
|
|
t.Errorf("got %v, wanted %v", have, want)
|
|
}
|
|
}
|