2024-01-10 17:05:12 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2023-09-22 16:51:15 +00:00
|
|
|
package meshv2beta1
|
2023-09-08 22:18:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2023-10-12 19:20:13 +00:00
|
|
|
func TestIsTransparentProxy(t *testing.T) {
|
2023-09-08 22:18:01 +00:00
|
|
|
cases := map[string]struct {
|
2023-10-12 19:20:13 +00:00
|
|
|
dynamicConfig *DynamicConfig
|
|
|
|
exp bool
|
2023-09-08 22:18:01 +00:00
|
|
|
}{
|
|
|
|
"nil dynamic config": {
|
2023-10-12 19:20:13 +00:00
|
|
|
dynamicConfig: nil,
|
|
|
|
exp: false,
|
2023-09-08 22:18:01 +00:00
|
|
|
},
|
|
|
|
"default mode": {
|
2023-10-12 19:20:13 +00:00
|
|
|
dynamicConfig: &DynamicConfig{
|
|
|
|
Mode: ProxyMode_PROXY_MODE_DEFAULT,
|
2023-09-08 22:18:01 +00:00
|
|
|
},
|
|
|
|
exp: false,
|
|
|
|
},
|
|
|
|
"direct mode": {
|
2023-10-12 19:20:13 +00:00
|
|
|
dynamicConfig: &DynamicConfig{
|
|
|
|
Mode: ProxyMode_PROXY_MODE_DEFAULT,
|
2023-09-08 22:18:01 +00:00
|
|
|
},
|
|
|
|
exp: false,
|
|
|
|
},
|
|
|
|
"transparent mode": {
|
2023-10-12 19:20:13 +00:00
|
|
|
dynamicConfig: &DynamicConfig{
|
|
|
|
Mode: ProxyMode_PROXY_MODE_TRANSPARENT,
|
2023-09-08 22:18:01 +00:00
|
|
|
},
|
|
|
|
exp: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, c := range cases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2023-10-12 19:20:13 +00:00
|
|
|
proxyCfg := &ProxyConfiguration{
|
|
|
|
DynamicConfig: c.dynamicConfig,
|
|
|
|
}
|
|
|
|
compProxyCfg := &ComputedProxyConfiguration{
|
|
|
|
DynamicConfig: c.dynamicConfig,
|
|
|
|
}
|
|
|
|
require.Equal(t, c.exp, proxyCfg.IsTransparentProxy())
|
|
|
|
require.Equal(t, c.exp, compProxyCfg.IsTransparentProxy())
|
2023-09-08 22:18:01 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|