youtu_grpc/pkg/config/get_config_test.go
2025-02-10 17:30:29 +08:00

45 lines
1.0 KiB
Go

package config
import (
"encoding/json"
"fmt"
"testing"
)
func TestGetConfig(t *testing.T) {
type args struct {
c *Config
serverName string
}
tests := []struct {
name string
args args
wantErr bool
}{
// TODO: Add test cases.
{"test", args{c: &Config{}, serverName: "test"}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := GetConfig(tt.args.c, tt.args.serverName); (err != nil) != tt.wantErr {
t.Errorf("GetConfig() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestGenConfig(t *testing.T) {
var c Config
c.RpcServerConf.ListenOn = "0.0.0.0:8081"
c.Mode = "dev"
c.Mysql = "root:youtu!0113@tcp(192.168.0.47:3306)/ecpm?charset=utf8mb4&parseTime=True&loc=Local"
c.Redis = []Redis{{Host: "192.168.0.47:2379:6379"}}
c.RpcServerConf.Etcd.Hosts = append(c.RpcServerConf.Etcd.Hosts, "192.168.0.47:2379")
c.RpcServerConf.Etcd.Key = "user_management.rpc"
b, err := json.Marshal(c)
if err != nil {
t.Fatal(err)
}
fmt.Println(string(b))
}