Skip to content

Commit

Permalink
Test configuration loading more precisely
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Nov 15, 2023
1 parent 184223c commit 37e3562
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions pkg/config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import (
v1 "github.com/fatedier/frp/pkg/config/v1"
)

func TestLoadConfigure(t *testing.T) {
require := require.New(t)
content := `
const TOML_SERVER_CONTENT = `
bindAddr = "127.0.0.1"
kcpBindPort = 7000
quicBindPort = 7001
Expand All @@ -33,13 +31,40 @@ custom404Page = "/abc.html"
transport.tcpKeepalive = 10
`

svrCfg := v1.ServerConfig{}
err := LoadConfigure([]byte(content), &svrCfg)
require.NoError(err)
require.EqualValues("127.0.0.1", svrCfg.BindAddr)
require.EqualValues(7000, svrCfg.KCPBindPort)
require.EqualValues(7001, svrCfg.QUICBindPort)
require.EqualValues(7005, svrCfg.TCPMuxHTTPConnectPort)
require.EqualValues("/abc.html", svrCfg.Custom404Page)
require.EqualValues(10, svrCfg.Transport.TCPKeepAlive)
const YAML_SERVER_CONTENT = `
bindAddr: 127.0.0.1
kcpBindPort: 7000
quicBindPort: 7001
tcpmuxHTTPConnectPort: 7005
custom404Page: /abc.html
transport:
tcpKeepalive: 10
`

const JSON_SERVER_CONTENT = `
{
"bindAddr": "127.0.0.1",
"kcpBindPort": 7000,
"quicBindPort": 7001,
"tcpmuxHTTPConnectPort": 7005,
"custom404Page": "/abc.html",
"transport": {
"tcpKeepalive": 10
}
}
`

func TestLoadServerConfig(t *testing.T) {
for _, content := range []string{TOML_SERVER_CONTENT, YAML_SERVER_CONTENT, JSON_SERVER_CONTENT} {
svrCfg := v1.ServerConfig{}
err := LoadConfigure([]byte(content), &svrCfg)
require := require.New(t)
require.NoError(err)
require.EqualValues("127.0.0.1", svrCfg.BindAddr)
require.EqualValues(7000, svrCfg.KCPBindPort)
require.EqualValues(7001, svrCfg.QUICBindPort)
require.EqualValues(7005, svrCfg.TCPMuxHTTPConnectPort)
require.EqualValues("/abc.html", svrCfg.Custom404Page)
require.EqualValues(10, svrCfg.Transport.TCPKeepAlive)
}
}

0 comments on commit 37e3562

Please sign in to comment.