75 lines
1.1 KiB
Go
75 lines
1.1 KiB
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func setup() {
|
||
|
configFile := "./testconf.json"
|
||
|
config := `{
|
||
|
"host": "127.0.0.1",
|
||
|
"port": 8080,
|
||
|
"logging": {
|
||
|
"categories": {
|
||
|
"default": {
|
||
|
"level": "error",
|
||
|
"appenders": ["out"]
|
||
|
}
|
||
|
},
|
||
|
"appenders": {
|
||
|
"out": {
|
||
|
"type": "console"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}`
|
||
|
os.WriteFile(configFile, []byte(config), 0644)
|
||
|
}
|
||
|
|
||
|
func teardown() {
|
||
|
configFile := "./testconf.json"
|
||
|
os.Remove(configFile)
|
||
|
}
|
||
|
func TestLoadConfig(t *testing.T) {
|
||
|
setup()
|
||
|
type args struct {
|
||
|
configFile string
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
}{
|
||
|
{
|
||
|
name: "testload",
|
||
|
args: args{
|
||
|
configFile: "./testconf.json",
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
LoadConfig(tt.args.configFile)
|
||
|
})
|
||
|
}
|
||
|
teardown()
|
||
|
}
|
||
|
|
||
|
func TestGetConfig(t *testing.T) {
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
want *ServerConfig
|
||
|
}{
|
||
|
// TODO: Add test cases.
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
if got := GetConfig(); !reflect.DeepEqual(got, tt.want) {
|
||
|
t.Errorf("GetConfig() = %v, want %v", got, tt.want)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|