mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #14711 from clarkfw/functional-options-pattern-EtcdProcessClusterConfig-1
tests: refactor `EtcdProcessClusterConfig` using Functional Options Pattern
This commit is contained in:
commit
4d15f5074c
@ -47,80 +47,64 @@ const (
|
|||||||
var testNameCleanRegex = regexp.MustCompile(`[^a-zA-Z0-9 \-_]+`)
|
var testNameCleanRegex = regexp.MustCompile(`[^a-zA-Z0-9 \-_]+`)
|
||||||
|
|
||||||
func NewConfigNoTLS() *EtcdProcessClusterConfig {
|
func NewConfigNoTLS() *EtcdProcessClusterConfig {
|
||||||
return &EtcdProcessClusterConfig{ClusterSize: 3,
|
return DefaultConfig()
|
||||||
InitialToken: "new",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigAutoTLS() *EtcdProcessClusterConfig {
|
func NewConfigAutoTLS() *EtcdProcessClusterConfig {
|
||||||
return &EtcdProcessClusterConfig{
|
return NewConfig(
|
||||||
ClusterSize: 3,
|
WithIsPeerTLS(true),
|
||||||
IsPeerTLS: true,
|
WithIsPeerAutoTLS(true),
|
||||||
IsPeerAutoTLS: true,
|
)
|
||||||
InitialToken: "new",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigTLS() *EtcdProcessClusterConfig {
|
func NewConfigTLS() *EtcdProcessClusterConfig {
|
||||||
return &EtcdProcessClusterConfig{
|
return NewConfig(
|
||||||
ClusterSize: 3,
|
WithClientTLS(ClientTLS),
|
||||||
ClientTLS: ClientTLS,
|
WithIsPeerTLS(true),
|
||||||
IsPeerTLS: true,
|
)
|
||||||
InitialToken: "new",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigClientTLS() *EtcdProcessClusterConfig {
|
func NewConfigClientTLS() *EtcdProcessClusterConfig {
|
||||||
return &EtcdProcessClusterConfig{
|
return NewConfig(WithClientTLS(ClientTLS))
|
||||||
ClusterSize: 3,
|
|
||||||
ClientTLS: ClientTLS,
|
|
||||||
InitialToken: "new",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigClientAutoTLS() *EtcdProcessClusterConfig {
|
func NewConfigClientAutoTLS() *EtcdProcessClusterConfig {
|
||||||
return &EtcdProcessClusterConfig{
|
return NewConfig(
|
||||||
ClusterSize: 1,
|
WithClusterSize(1),
|
||||||
IsClientAutoTLS: true,
|
WithIsClientAutoTLS(true),
|
||||||
ClientTLS: ClientTLS,
|
WithClientTLS(ClientTLS),
|
||||||
InitialToken: "new",
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigPeerTLS() *EtcdProcessClusterConfig {
|
func NewConfigPeerTLS() *EtcdProcessClusterConfig {
|
||||||
return &EtcdProcessClusterConfig{
|
return NewConfig(
|
||||||
ClusterSize: 3,
|
WithIsPeerTLS(true),
|
||||||
IsPeerTLS: true,
|
)
|
||||||
InitialToken: "new",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigClientTLSCertAuth() *EtcdProcessClusterConfig {
|
func NewConfigClientTLSCertAuth() *EtcdProcessClusterConfig {
|
||||||
return &EtcdProcessClusterConfig{
|
return NewConfig(
|
||||||
ClusterSize: 1,
|
WithClusterSize(1),
|
||||||
ClientTLS: ClientTLS,
|
WithClientTLS(ClientTLS),
|
||||||
InitialToken: "new",
|
WithClientCertAuthEnabled(true),
|
||||||
ClientCertAuthEnabled: true,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigClientTLSCertAuthWithNoCN() *EtcdProcessClusterConfig {
|
func NewConfigClientTLSCertAuthWithNoCN() *EtcdProcessClusterConfig {
|
||||||
return &EtcdProcessClusterConfig{
|
return NewConfig(
|
||||||
ClusterSize: 1,
|
WithClusterSize(1),
|
||||||
ClientTLS: ClientTLS,
|
WithClientTLS(ClientTLS),
|
||||||
InitialToken: "new",
|
WithClientCertAuthEnabled(true),
|
||||||
ClientCertAuthEnabled: true,
|
WithNoCN(true),
|
||||||
NoCN: true,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigJWT() *EtcdProcessClusterConfig {
|
func NewConfigJWT() *EtcdProcessClusterConfig {
|
||||||
return &EtcdProcessClusterConfig{
|
return NewConfig(
|
||||||
ClusterSize: 1,
|
WithClusterSize(1),
|
||||||
InitialToken: "new",
|
WithAuthTokenOpts("jwt,pub-key="+path.Join(FixturesDir, "server.crt")+
|
||||||
AuthTokenOpts: "jwt,pub-key=" + path.Join(FixturesDir, "server.crt") +
|
",priv-key="+path.Join(FixturesDir, "server.key.insecure")+",sign-method=RS256,ttl=1s"),
|
||||||
",priv-key=" + path.Join(FixturesDir, "server.key.insecure") + ",sign-method=RS256,ttl=1s",
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigStandalone(cfg EtcdProcessClusterConfig) *EtcdProcessClusterConfig {
|
func ConfigStandalone(cfg EtcdProcessClusterConfig) *EtcdProcessClusterConfig {
|
||||||
@ -186,6 +170,131 @@ type EtcdProcessClusterConfig struct {
|
|||||||
GoFailEnabled bool
|
GoFailEnabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DefaultConfig() *EtcdProcessClusterConfig {
|
||||||
|
return &EtcdProcessClusterConfig{
|
||||||
|
ClusterSize: 3,
|
||||||
|
InitialToken: "new",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewConfig(opts ...EPClusterOption) *EtcdProcessClusterConfig {
|
||||||
|
c := DefaultConfig()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(c)
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
type EPClusterOption func(*EtcdProcessClusterConfig)
|
||||||
|
|
||||||
|
func WithConfig(cfg *EtcdProcessClusterConfig) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { *c = *cfg }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithDataDirPath(path string) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.DataDirPath = path }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithKeepDataDir(keep bool) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.KeepDataDir = keep }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithSnapshotCount(count int) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.SnapshotCount = count }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithClusterSize(size int) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.ClusterSize = size }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithBaseScheme(scheme string) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.BaseScheme = scheme }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithBasePort(port int) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.BasePort = port }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithClientTLS(clientTLS ClientConnType) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.ClientTLS = clientTLS }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithClientCertAuthEnabled(enabled bool) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.ClientCertAuthEnabled = enabled }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithIsPeerTLS(isPeerTLS bool) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.IsPeerTLS = isPeerTLS }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithIsPeerAutoTLS(isPeerAutoTLS bool) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.IsPeerAutoTLS = isPeerAutoTLS }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithIsClientAutoTLS(isClientAutoTLS bool) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.IsClientAutoTLS = isClientAutoTLS }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithIsClientCRL(isClientCRL bool) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.IsClientCRL = isClientCRL }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithNoCN(noCN bool) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.NoCN = noCN }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithQuotaBackendBytes(bytes int64) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.QuotaBackendBytes = bytes }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithDisableStrictReconfigCheck(disable bool) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.DisableStrictReconfigCheck = disable }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithEnableV2(enable bool) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.EnableV2 = enable }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithAuthTokenOpts(token string) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.AuthTokenOpts = token }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithRollingStart(rolling bool) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.RollingStart = rolling }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithDiscovery(discovery string) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.Discovery = discovery }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithDiscoveryEndpoints(endpoints []string) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.DiscoveryEndpoints = endpoints }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithDiscoveryToken(token string) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.DiscoveryToken = token }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithLogLevel(level string) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.LogLevel = level }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithCorruptCheckTime(time time.Duration) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.CorruptCheckTime = time }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithCompactHashCheckEnabled(enabled bool) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.CompactHashCheckEnabled = enabled }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithCompactHashCheckTime(time time.Duration) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.CompactHashCheckTime = time }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithGoFailEnabled(enabled bool) EPClusterOption {
|
||||||
|
return func(c *EtcdProcessClusterConfig) { c.GoFailEnabled = enabled }
|
||||||
|
}
|
||||||
|
|
||||||
// NewEtcdProcessCluster launches a new cluster from etcd processes, returning
|
// NewEtcdProcessCluster launches a new cluster from etcd processes, returning
|
||||||
// a new EtcdProcessCluster once all nodes are ready to accept client requests.
|
// a new EtcdProcessCluster once all nodes are ready to accept client requests.
|
||||||
func NewEtcdProcessCluster(ctx context.Context, t testing.TB, cfg *EtcdProcessClusterConfig) (*EtcdProcessCluster, error) {
|
func NewEtcdProcessCluster(ctx context.Context, t testing.TB, cfg *EtcdProcessClusterConfig) (*EtcdProcessCluster, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user