31 lines
1.2 KiB
Go
31 lines
1.2 KiB
Go
package model
|
|
|
|
import "testing"
|
|
|
|
func TestPersistentTargetCapabilityValidation(t *testing.T) {
|
|
for _, protocol := range []string{"mysql", "mongodb", "pgsql", "redis", "http", "https", "ssh", "sftp", "sqlserver", "rabbitmq", "tcp"} {
|
|
for _, mode := range []string{"direct", "socks5", "ssh", "k8s"} {
|
|
for _, cluster := range []string{"single", "auto"} {
|
|
p := Proxy{Type: protocol, Outbound: Outbound{Mode: mode}, Cluster: ClusterConfig{Mode: cluster}, ConnectionOptions: ConnectionOptions{Persistent: true}}
|
|
if err := p.ValidateConnectionOptions(); err != nil {
|
|
t.Fatalf("%s/%s/%s should be supported: %v", protocol, mode, cluster, err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPersistentTargetRuntimeStateDoesNotPersist(t *testing.T) {
|
|
p := Proxy{ConnectionOptions: ConnectionOptions{Persistent: true}, PreparedTarget: func(Proxy) (*PreparedSession, bool) { t.Fatal("must not borrow"); return nil, false }}
|
|
if p.GatewayOnly().PreparedTarget != nil {
|
|
t.Fatal("runtime pool leaked into gateway config")
|
|
}
|
|
redacted, _ := p.Redacted()
|
|
if redacted.PreparedTarget != nil {
|
|
t.Fatal("runtime pool leaked into response")
|
|
}
|
|
if !TargetFromProxy(p).ConnectionOptions.Persistent {
|
|
t.Fatal("target setting lost")
|
|
}
|
|
}
|