| 9 | func TestProxyCloneDeepCopy(t *testing.T) { |
| 10 | require := require.New(t) |
| 11 |
| 12 | enabled := true |
| 13 | pluginHTTP2 := true |
| 14 | cfg := &HTTPProxyConfig{ |
| 15 | ProxyBaseConfig: ProxyBaseConfig{ |
| 16 | Name: "p1", |
| 17 | Type: "http", |
| 18 | Enabled: &enabled, |
| 19 | Annotations: map[string]string{"a": "1"}, |
| 20 | Metadatas: map[string]string{"m": "1"}, |
| 21 | HealthCheck: HealthCheckConfig{ |
| 22 | Type: "http", |
| 23 | HTTPHeaders: []HTTPHeader{ |
| 24 | {Name: "X-Test", Value: "v1"}, |
| 25 | }, |
| 26 | }, |
| 27 | ProxyBackend: ProxyBackend{ |
| 28 | Plugin: TypedClientPluginOptions{ |
| 29 | Type: PluginHTTPS2HTTP, |
| 30 | ClientPluginOptions: &HTTPS2HTTPPluginOptions{ |
| 31 | Type: PluginHTTPS2HTTP, |
| 32 | EnableHTTP2: &pluginHTTP2, |
| 33 | RequestHeaders: HeaderOperations{Set: map[string]string{"k": "v"}}, |
| 34 | }, |
| 35 | }, |
| 36 | }, |
| 37 | }, |
| 38 | DomainConfig: DomainConfig{ |
| 39 | CustomDomains: []string{"a.example.com"}, |
| 40 | SubDomain: "a", |
| 41 | }, |
| 42 | Locations: []string{"/api"}, |
| 43 | RequestHeaders: HeaderOperations{Set: map[string]string{"h1": "v1"}}, |
| 44 | ResponseHeaders: HeaderOperations{Set: map[string]string{"h2": "v2"}}, |
| 45 | } |
| 46 |
| 47 | cloned := cfg.Clone().(*HTTPProxyConfig) |
| 48 |
| 49 | *cloned.Enabled = false |
| 50 | cloned.Annotations["a"] = "changed" |
| 51 | cloned.Metadatas["m"] = "changed" |
| 52 | cloned.HealthCheck.HTTPHeaders[0].Value = "changed" |
| 53 | cloned.CustomDomains[0] = "b.example.com" |
| 54 | cloned.Locations[0] = "/new" |
| 55 | cloned.RequestHeaders.Set["h1"] = "changed" |
| 56 | cloned.ResponseHeaders.Set["h2"] = "changed" |
| 57 | clientPlugin := cloned.Plugin.ClientPluginOptions.(*HTTPS2HTTPPluginOptions) |
| 58 | *clientPlugin.EnableHTTP2 = false |
| 59 | clientPlugin.RequestHeaders.Set["k"] = "changed" |
| 60 |
| 61 | require.True(*cfg.Enabled) |
| 62 | require.Equal("1", cfg.Annotations["a"]) |
| 63 | require.Equal("1", cfg.Metadatas["m"]) |
| 64 | require.Equal("v1", cfg.HealthCheck.HTTPHeaders[0].Value) |
| 65 | require.Equal("a.example.com", cfg.CustomDomains[0]) |
| 66 | require.Equal("/api", cfg.Locations[0]) |
| 67 | require.Equal("v1", cfg.RequestHeaders.Set["h1"]) |
| 68 | require.Equal("v2", cfg.ResponseHeaders.Set["h2"]) |
| 69 |
| 70 | origPlugin := cfg.Plugin.ClientPluginOptions.(*HTTPS2HTTPPluginOptions) |
| 71 | require.True(*origPlugin.EnableHTTP2) |
| 72 | require.Equal("v", origPlugin.RequestHeaders.Set["k"]) |
| 73 | } |
| 74 |
| 75 | func TestVisitorCloneDeepCopy(t *testing.T) { |
| 76 | require := require.New(t) |
| 77 |
| 78 | enabled := true |
| 79 | cfg := &XTCPVisitorConfig{ |
| 80 | VisitorBaseConfig: VisitorBaseConfig{ |
| 81 | Name: "v1", |
| 82 | Type: "xtcp", |
| 83 | Enabled: &enabled, |
| 84 | ServerName: "server", |
| 85 | BindPort: 7000, |
| 86 | Plugin: TypedVisitorPluginOptions{ |
| 87 | Type: VisitorPluginVirtualNet, |
| 88 | VisitorPluginOptions: &VirtualNetVisitorPluginOptions{ |
| 89 | Type: VisitorPluginVirtualNet, |
| 90 | DestinationIP: "10.0.0.1", |
| 91 | }, |
| 92 | }, |
| 93 | }, |
| 94 | NatTraversal: &NatTraversalConfig{ |
| 95 | DisableAssistedAddrs: true, |
| 96 | }, |
| 97 | } |
| 98 |
| 99 | cloned := cfg.Clone().(*XTCPVisitorConfig) |
| 100 | *cloned.Enabled = false |
| 101 | cloned.NatTraversal.DisableAssistedAddrs = false |
| 102 | visitorPlugin := cloned.Plugin.VisitorPluginOptions.(*VirtualNetVisitorPluginOptions) |
| 103 | visitorPlugin.DestinationIP = "10.0.0.2" |
| 104 |
| 105 | require.True(*cfg.Enabled) |
| 106 | require.True(cfg.NatTraversal.DisableAssistedAddrs) |
| 107 | origPlugin := cfg.Plugin.VisitorPluginOptions.(*VirtualNetVisitorPluginOptions) |
| 108 | require.Equal("10.0.0.1", origPlugin.DestinationIP) |
| 109 | } |