proxy_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2023 The frp Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package v1
  15. import (
  16. "encoding/json"
  17. "testing"
  18. "github.com/stretchr/testify/require"
  19. )
  20. func TestUnmarshalTypedProxyConfig(t *testing.T) {
  21. require := require.New(t)
  22. proxyConfigs := struct {
  23. Proxies []TypedProxyConfig `json:"proxies,omitempty"`
  24. }{}
  25. strs := `{
  26. "proxies": [
  27. {
  28. "type": "tcp",
  29. "localPort": 22,
  30. "remotePort": 6000
  31. },
  32. {
  33. "type": "http",
  34. "localPort": 80,
  35. "customDomains": ["www.example.com"]
  36. }
  37. ]
  38. }`
  39. err := json.Unmarshal([]byte(strs), &proxyConfigs)
  40. require.NoError(err)
  41. require.IsType(&TCPProxyConfig{}, proxyConfigs.Proxies[0].ProxyConfigurer)
  42. require.IsType(&HTTPProxyConfig{}, proxyConfigs.Proxies[1].ProxyConfigurer)
  43. }