36 lines
498 B
Go
36 lines
498 B
Go
package utils
|
|
|
|
import (
|
|
"gopkg.in/yaml.v2"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
type config struct {
|
|
Version int
|
|
Mapping map[string]string
|
|
}
|
|
|
|
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: map[string]string{
|
|
"key": "value1",
|
|
"key2": "value2",
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Log(err)
|
|
return
|
|
}
|
|
}
|