Files
2021-12-28 10:57:13 +08:00

39 lines
523 B
Go

package utils
import (
"gopkg.in/yaml.v2"
"os"
"testing"
)
type Mysql struct {
Host string
}
type config struct {
Version int `yaml:"version"`
Mapping *Mysql `yaml:"mapping"`
}
func TestNewFile(t *testing.T) {
file, err := os.OpenFile("test.yml", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
t.Log(err)
return
}
defer file.Close()
enc := yaml.NewEncoder(file)
err = enc.Encode(config{
Version: 7,
Mapping: &Mysql{
Host: "123",
},
})
if err != nil {
t.Log(err)
return
}
}