60 lines
822 B
Go
60 lines
822 B
Go
package utils
|
|
|
|
import (
|
|
"gopkg.in/yaml.v2"
|
|
"io"
|
|
"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
|
|
}
|
|
}
|
|
|
|
func TestNewOpenFile(t *testing.T) {
|
|
file, err := os.Open("BizChat(1).db-shm")
|
|
|
|
if err != nil {
|
|
t.Log(err)
|
|
return
|
|
}
|
|
defer file.Close()
|
|
|
|
_bytes := make([]byte, 0)
|
|
|
|
if _bytes, err = io.ReadAll(file); err != nil {
|
|
t.Log(err)
|
|
return
|
|
}
|
|
t.Log(_bytes)
|
|
|
|
t.Log(string(_bytes[0:2]))
|
|
}
|