Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
postgres-operator
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
zalando
postgres-operator
Commits
8967a3be
Commit
8967a3be
authored
Mar 27, 2018
by
erthalion
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for load balancer function logic
parent
ced770a8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/cluster/k8sres_test.go
+94
-0
94 additions, 0 deletions
pkg/cluster/k8sres_test.go
with
94 additions
and
0 deletions
pkg/cluster/k8sres_test.go
0 → 100644
+
94
−
0
View file @
8967a3be
package
cluster
import
(
"github.com/zalando-incubator/postgres-operator/pkg/spec"
"github.com/zalando-incubator/postgres-operator/pkg/util/config"
"github.com/zalando-incubator/postgres-operator/pkg/util/k8sutil"
"testing"
)
func
True
()
*
bool
{
b
:=
true
return
&
b
}
func
False
()
*
bool
{
b
:=
false
return
&
b
}
func
TestCreateLoadBalancerLogic
(
t
*
testing
.
T
)
{
var
cluster
=
New
(
Config
{
OpConfig
:
config
.
Config
{
ProtectedRoles
:
[]
string
{
"admin"
},
Auth
:
config
.
Auth
{
SuperUsername
:
superUserName
,
ReplicationUsername
:
replicationUserName
,
},
},
},
k8sutil
.
KubernetesClient
{},
spec
.
Postgresql
{},
logger
)
testName
:=
"TestCreateLoadBalancerLogic"
tests
:=
[]
struct
{
subtest
string
role
PostgresRole
spec
*
spec
.
PostgresSpec
opConfig
config
.
Config
result
bool
}{
{
subtest
:
"new format, load balancer is enabled for replica"
,
role
:
Replica
,
spec
:
&
spec
.
PostgresSpec
{
EnableReplicaLoadBalancer
:
True
()},
opConfig
:
config
.
Config
{},
result
:
true
,
},
{
subtest
:
"new format, load balancer is disabled for replica"
,
role
:
Replica
,
spec
:
&
spec
.
PostgresSpec
{
EnableReplicaLoadBalancer
:
False
()},
opConfig
:
config
.
Config
{},
result
:
false
,
},
{
subtest
:
"new format, load balancer isn't specified for replica"
,
role
:
Replica
,
spec
:
&
spec
.
PostgresSpec
{
EnableReplicaLoadBalancer
:
nil
},
opConfig
:
config
.
Config
{
EnableReplicaLoadBalancer
:
true
},
result
:
true
,
},
{
subtest
:
"new format, load balancer isn't specified for replica"
,
role
:
Replica
,
spec
:
&
spec
.
PostgresSpec
{
EnableReplicaLoadBalancer
:
nil
},
opConfig
:
config
.
Config
{
EnableReplicaLoadBalancer
:
false
},
result
:
false
,
},
{
subtest
:
"old format, load balancer is enabled for replica"
,
role
:
Replica
,
spec
:
&
spec
.
PostgresSpec
{
ReplicaLoadBalancer
:
True
()},
opConfig
:
config
.
Config
{},
result
:
true
,
},
{
subtest
:
"old format has priority"
,
role
:
Replica
,
spec
:
&
spec
.
PostgresSpec
{
ReplicaLoadBalancer
:
True
(),
EnableReplicaLoadBalancer
:
False
(),
},
opConfig
:
config
.
Config
{},
result
:
true
,
},
}
for
_
,
tt
:=
range
tests
{
cluster
.
OpConfig
=
tt
.
opConfig
result
:=
cluster
.
shouldCreateLoadBalancerForService
(
tt
.
role
,
tt
.
spec
)
if
tt
.
result
!=
result
{
t
.
Errorf
(
"%s %s: Load balancer is %t, expect %t for role %#v and spec %#v"
,
testName
,
tt
.
subtest
,
result
,
tt
.
result
,
tt
.
role
,
tt
.
spec
)
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment