fix: ClientConfig marshals incorrectly
This commit is contained in:
parent
596262d5e0
commit
4712e3a639
@ -189,6 +189,10 @@ func (c *TypedProxyConfig) UnmarshalJSON(b []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *TypedProxyConfig) MarshalJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(c.ProxyConfigurer)
|
||||||
|
}
|
||||||
|
|
||||||
type ProxyConfigurer interface {
|
type ProxyConfigurer interface {
|
||||||
Complete(namePrefix string)
|
Complete(namePrefix string)
|
||||||
GetBaseConfig() *ProxyBaseConfig
|
GetBaseConfig() *ProxyBaseConfig
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUnmarshalTypedProxyConfig(t *testing.T) {
|
func TestUnmarshalTypedProxyConfig(t *testing.T) {
|
||||||
@ -47,3 +48,58 @@ func TestUnmarshalTypedProxyConfig(t *testing.T) {
|
|||||||
require.IsType(&TCPProxyConfig{}, proxyConfigs.Proxies[0].ProxyConfigurer)
|
require.IsType(&TCPProxyConfig{}, proxyConfigs.Proxies[0].ProxyConfigurer)
|
||||||
require.IsType(&HTTPProxyConfig{}, proxyConfigs.Proxies[1].ProxyConfigurer)
|
require.IsType(&HTTPProxyConfig{}, proxyConfigs.Proxies[1].ProxyConfigurer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMarshalTypedProxyConfig(t *testing.T) {
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
clientConfig := ClientConfig{
|
||||||
|
ClientCommonConfig: ClientCommonConfig{
|
||||||
|
Auth: AuthClientConfig{
|
||||||
|
Method: AuthMethodToken,
|
||||||
|
Token: "update-me",
|
||||||
|
},
|
||||||
|
ServerAddr: "frp.example.org",
|
||||||
|
ServerPort: 8080,
|
||||||
|
Log: LogConfig{
|
||||||
|
Level: "info",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Proxies: []TypedProxyConfig{
|
||||||
|
{
|
||||||
|
Type: string(ProxyTypeTCP),
|
||||||
|
ProxyConfigurer: &TCPProxyConfig{
|
||||||
|
ProxyBaseConfig: ProxyBaseConfig{
|
||||||
|
Name: "proxy1",
|
||||||
|
Type: string(ProxyTypeTCP),
|
||||||
|
ProxyBackend: ProxyBackend{
|
||||||
|
LocalIP: "192.168.0.101",
|
||||||
|
LocalPort: 8889,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 30001,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: string(ProxyTypeTCP),
|
||||||
|
ProxyConfigurer: &TCPProxyConfig{
|
||||||
|
ProxyBaseConfig: ProxyBaseConfig{
|
||||||
|
Name: "proxy2",
|
||||||
|
Type: string(ProxyTypeTCP),
|
||||||
|
ProxyBackend: ProxyBackend{
|
||||||
|
LocalIP: "192.168.0.102",
|
||||||
|
LocalPort: 8889,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 30002,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
yamlConfig, err := yaml.Marshal(&clientConfig)
|
||||||
|
require.NoError(err)
|
||||||
|
clientConfigUnmarshalled := ClientConfig{}
|
||||||
|
err = yaml.Unmarshal(yamlConfig, &clientConfigUnmarshalled)
|
||||||
|
require.NoError(err)
|
||||||
|
require.Equal(clientConfig, clientConfigUnmarshalled)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user