123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package config
- import (
- "bytes"
- "fmt"
- "io"
- "os"
- "path"
- "runtime"
- "testing"
- )
- func getCurrentPath() string {
- _, filename, _, _ := runtime.Caller(1)
- return path.Dir(filename)
- }
- func TestOpenFile(t *testing.T) {
- fmt.Println(getCurrentPath())
- config := configFile{}
- config.openConfigFile(`C:\Program_GT\Code\Go\Work\xg_autodeploy\file\config.toml`)
- }
- func TestParseConfing(t *testing.T) {
- InitNodeSetting(`C:\Program_GT\Code\Go\Work\xg_autodeploy\file\config.toml`)
- }
- func TestSetXuguini(t *testing.T) {
- config := InitNodeSetting(`C:\Program_GT\Code\Go\Work\xg_autodeploy\file\config.toml`)
- // 打开文件
- file, err := os.Open(`C:\Program_GT\Code\Go\Work\xg_autodeploy\file\xugu.ini`)
- if err != nil {
- panic(err)
- }
- defer file.Close()
- // 创建一个 bytes.Buffer
- buf := new(bytes.Buffer)
- // 将文件内容复制到 buf 中
- if _, err := io.Copy(buf, file); err != nil {
- panic(err)
- }
- SetXginiBuffer(buf, config.xginiMap)
- err = os.WriteFile("output1.txt", buf.Bytes(), 0644)
- if err != nil {
- fmt.Println("Error writing file:", err)
- return
- }
- }
|